Passer au contenu principal

addListener()

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

Description

Registers a component to listen to an event.

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)