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
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 referenceAPI
obj.addEventListener(channel, callback): void
obj.removeEventListener(channel, callback): voidChannels 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.
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, 2DScene2D/Node2D— pointer events (click,touchstart), physics contact events device—resizeAudioPlayer/VideoPlayer—completed,loopReachedWebSocket—open,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:
UIButton('Play').onClick(() => start()) // UI: chainable on* setter
ball.addEventListener('click', () => kick()) // scenes/nodes: addEventListenerSee also
- Pointer events & gestures — the
click/touchstartevent objects - Conventions — the events rule in context