Passer au contenu principal

removeListener()

world.events.removeListener(target, name, listener)

Description

Un-registers an existing listener. The eid, name, and exact reference to the listener callback is needed to remove the listener.

Parameters

PropertyTypeDescription
targeteidThe eid of the entity that the listener is attached to.
namestringThe name of the event that the entity is listening for.
listenerfunctionThe function that gets triggered when the event name is dispatched to the target entity or a entity that is a child of the entity the listener is attached to.

Returns

None.

Example

const handleCollision = (e) => { console.log("I touched another entity") }

// This listener logs a message whenever the entity collides with another entity.
world.events.addListener(component.eid, ecs.physics.COLLISION_START_EVENT, handleCollision)

// This line removes the listener
world.events.removeListener(component.eid, ecs.physics.COLLISION_START_EVENT, handleCollision)