ReferenceScripting APIMotionSceneon
MotionScene.on
methodListens for something happening.
| Name | on |
|---|---|
| Kind | method of MotionScene |
| Called as | scene.on(…) |
| Since | 0.3 |
Syntax
on<E extends keyof MotionEvents>( event: E, fn: MotionEvents[E], options?: MotionEventOptions): () => voidParameters
| Name | Type | Description |
|---|---|---|
event | E | What to listen for: click, press, pointer, beat, tick, props... (the Events) |
fn | MotionEvents[E] | What runs, with what the event hands it |
options | MotionEventOptions | Optional. For loud and quiet: how loud (level) and how long (seconds) |
Returns
() => void: a function that stops listening.
Remarks
Throws for an event there's no such thing as.
Example
scene.on("click", (x, y) => scene.particles("Sparks").burst(50, { x, y }));See also
MotionEvents · MotionEventOptions · In examples: Constellations, Kelp Forest, Pulse, Rain Harbour, Resonance, Valley Hours, Vent Garden
Notes from the community
Written by creators and checked by the docs' editors. Not part of Motion's official reference.