addListener()
world.events.addListener(target, name, listener)
Description
Registers a component to listen to an event.
Parameters
Property | Type | Description |
---|---|---|
target | eid | The eid of the entity that the listener is attached to. |
name | string | The name of the event that the entity is listening for. |
listener | function | The 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)