LeCodesdocs

Events

The listener pattern shared across the SDK. There is no Emitter global to construct — this page documents the two methods every event-bearing object exposes and how they behave. UI elements are the exception: they use chainable on* methods instead (see below).

At a glance

TypeScript
scene.addEventListener('click', ev => console.log(ev.clientX, ev.clientY))

const onDone = () => next()
player.addEventListener('completed', onDone)
player.removeEventListener('completed', onDone)   // remove by the SAME function reference

API

TypeScript
obj.addEventListener(channel, callback): void
obj.removeEventListener(channel, callback): void

Channels and callback signatures are typed per object (a node's 'click' delivers a ClickEvent, a media player's 'completed' delivers nothing). Removal matches by function identity — keep a reference to any callback you'll need to remove.

Note

there is no once() and no public dispatch — only the owning object emits its own events. Adding the same callback twice calls it twice. Removing a listener from inside a callback is safe (dispatch iterates a snapshot).

Who exposes it

  • 3D Scene / Node, 2D Scene2D / Node2D — pointer events (click, touchstart), physics contact events
  • deviceresize
  • AudioPlayer / VideoPlayercompleted, loopReached
  • WebSocketopen, message, close, error

UI is different: on* methods

UI elements don't use addEventListener; they take callbacks through chainable on* methods so handlers slot into the build chain:

TypeScript
UIButton('Play').onClick(() => start())          // UI: chainable on* setter
ball.addEventListener('click', () => kick())     // scenes/nodes: addEventListener

See also