events-system
Use this skill when working with the Phaser 4 event system. Covers EventEmitter, scene events, game events, custom events, and event-driven communication. Triggers on: events, on, emit, EventEmitter, scene events, listeners.
By phaserjs · 523 installs
npx skills add phaserjs/phaser --skill events-system
Source repository · Upstream listing
Events System
Phaser uses the EventEmitter pattern (via eventemitter3) throughout the entire framework. Every major system Game, Scene, Input, Loader, Cameras, Sound, Tweens, Physics, Textures, Animations is an EventEmitter or contains one. Events use lowercase string keys. Phaser provides named constants for all built in events to avoid typos and enable IDE autocomplete.
Key source paths: src/events/EventEmitter.js , src/scene/events/ , src/core/events/ , src/input/events/ , src/loader/events/ , src/animations/events/ , src/cameras/2d/events/ , src/sound/events/ , src/tweens/events/ , src/physics/arcade/events/ , src/textures/events/ , src/gameobjects/events/ , src/time/events/
Related skills: ../scenes/SKILL.md, ../input keyboard mouse touch/SKILL.md
Quick Start
Using Named Constants (Preferred)
Core Concepts
EventEmitter Base Class
Phaser.Events.EventEmitter extends eventemitter3. It adds shutdown() and destroy() methods that both call removeAllListeners() .
Full API (inherited from eventemitter3):
Method Description
on(event, fn, context?) Add persistent listener. Returns this for chaining
addListener(event, fn, context?) Alias for on
once(event, fn, context?) Add one time listener; auto removed after first fire
off(event, fn?, context?, once?) Remove listener(s). Must pass same fn reference to remove specific listener
removeListener(event, fn?, context?, once?) Alias for off
removeAllListeners(event?) Remove all listeners for event, or all events if no arg
emit(event, ...args) Fire event. Returns true if it had listeners
listeners(event) Return array of listener functions for an event
listenerCount(event) Return number of listeners for an event
eventNames() Return array of event names that have listeners
shutdown() Calls removeAllListeners()
destroy() Calls removeAllListeners()
Event Strings vs Constants
Every built in event is a lowercase string exported as a constant. The constant name maps predictably to the string:
Some events use a key suffix pattern for per key listening:
Context (Third Argument)
The third argument to on / once sets this inside the callback. Defaults to the emitter.
Common Patterns
Scene Lifecycle Events
Frame loop order: preupdate update Scene.update() postupdate prerender render
Game Level Events
Inter Scene Communication
Custom Events
All Event Namespaces Reference
Scene Events ( Phaser.Scenes.Events )
Emitter: this.events (the Scene's Systems EventEmitter)
Constant String When
BOOT 'boot' Scene Systems boot (for plugins)
READY 'ready' Scene Systems fully ready
START 'start' Scene starts running
CREATE 'create' After Scene.create() completes
PRE UPDATE 'preupdate' Before update each frame
UPDATE 'update' Main update each frame
POST UPDATE 'postupdate' After update each frame
PRE RENDER 'prerender' Before render each frame
RENDER 'render' During render each frame
PAUSE 'pause' Scene paused
RESUME 'resume' Scene resumed from pause
SLEEP 'sleep' Scene put to sleep
WAKE 'wake' Scene woken from sleep
SHUTDOWN 'shutdown' Scene shutting down (may restart)
DESTROY 'destroy' Scene permanently destroyed
ADDED TO SCENE 'addedtoscene' GameObject added to scene
REMOVED FROM SCENE 'removedfromscene' GameObject removed from scene
TRANSITION INIT 'transitioninit' Transition initialized (target scene)
TRANSITION START 'transitionstart' Transition started (target scene)
TRANSITION OUT 'transitionout' Transition out (source scene)
TRANSITION COMPLETE 'transitioncomplete' Transition finished
TRANSITION WAKE 'transitionwake' Transition wakes target scene
Game Events ( Phaser.Core.Events )
Emitter: this.game.events or game.events
Constant String When
BOOT 'boot' Game instance finished booting
READY 'ready' Game ready to start running
SYSTEM READY 'systemready' All global systems ready
PRE STEP 'prestep' Before game loop step
STEP 'step' Main game loop step
POST STEP 'poststep' After game loop step
PRE RENDER 'prerender' Before rendering all scenes
POST RENDER 'postrender' After rendering all scenes
PAUSE 'pause' Game paused
RESUME 'resume' Game resumed
BLUR 'blur' Browser tab lost focus
FOCUS 'focus' Browser tab gained focus
HIDDEN 'hidden' Page Visibility API: hidden
VISIBLE 'visible' Page Visibility API: visible
CONTEXT LOST 'contextlost' WebGL context lost
DESTROY 'destroy' Game being destroyed
Input Events ( Phaser.Input.Events )
Emitter: this.input (scene level) or individual GameObjects. Events exist at three levels: scene level ( this.input ), scene level with gameobject prefix, and directly on interactive GameObjects. See ../input keyboard mouse touch/SKILL.md for full usage.
Scene level pointer events (on this.input ):
POINTER DOWN 'pointerdown' POINTER UP 'pointerup' POINTER MOVE 'pointermove' POINTER OVER 'pointerover' POINTER OUT 'pointerout' POINTER WHEEL 'wheel' POINTER DOWN OUTSIDE 'pointerdownoutside' POINTER UP OUTSIDE 'pointerupoutside'
Scene level gameobject events (on this.input ):
GAMEOBJECT DOWN 'gameobjectdown' GAMEOBJECT UP 'gameobjectup' GAMEOBJECT MOVE 'gameobjectmove' GAMEOBJECT OVER 'gameobjectover' GAMEOBJECT OUT 'gameobjectout' GAMEOBJECT WHEEL 'gameobjectwheel'
Per GameObject events (emitted on the GameObject itself, requires setInteractive() ):
GAMEOBJECT POINTER DOWN 'pointerdown' GAMEOBJECT POINTER UP 'pointerup' GAMEOBJECT POINTER MOVE 'pointermove' GAMEOBJECT POINTER OVER 'pointerover' GAMEOBJECT POINTER OUT 'pointerout' GAMEOBJECT POINTER WHEEL 'wheel'
Drag events (on this.input and on GameObjects with same string):
DRAG START / GAMEOBJECT DRAG START 'dragstart' DRAG / GAMEOBJECT DRAG 'drag' DRAG END / GAMEOBJECT DRAG END 'dragend' DRAG ENTER / GAMEOBJECT DRAG ENTER 'dragenter' DRAG OVER / GAMEOBJECT DRAG OVER 'dragover' DRAG LEAVE / GAMEOBJECT DRAG LEAVE 'dragleave' DROP / GAMEOBJECT DROP 'drop'
Other: GAME OUT 'gameout' GAME OVER 'gameover' POINTERLOCK CHANGE 'pointerlockchange'
Loader Events ( Phaser.Loader.Events )
Emitter: this.load
Constant String When
ADD 'addfile' File added to load queue
START 'start' Loader starts
PROGRESS 'progress' Overall progress updated (0 1)
FILE LOAD 'load' Individual file loaded
FILE PROGRESS 'fileprogress' Individual file progress
FILE COMPLETE 'filecomplete' Individual file completed processing
FILE KEY COMPLETE 'filecomplete ' Specific file completed (append type key )
FILE LOAD ERROR 'loaderror' File failed to load
POST PROCESS 'postprocess' All files loaded, post processing
COMPLETE 'complete' All loading complete
Animation Events ( Phaser.Animations.Events )
Emitter: individual sprites (per sprite) or this.anims (global AnimationManager)
Constant String When
ADD ANIMATION 'add' Animation added to manager
REMOVE ANIMATION 'remove' Animation removed from manager
PAUSE ALL 'pauseall' All animations paused
RESUME ALL 'resumeall' All animations resumed
ANIMATION START 'animationstart' Animation starts playing on a sprite
ANIMATION RESTART 'animationrestart' Animation restarts on a sprite
ANIMATION REPEAT 'animationrepeat' Animation repeats on a sprite
ANIMATION UPDATE 'animationupdate' Animation frame changes on a sprite
ANIMATION COMPLETE 'animationcomplete' Animation finishes on a sprite
ANIMATION COMPLETE KEY 'animationcomplete ' Specific animation finishes (append key)
ANIMATION STOP 'animationstop' Animation stopped on a sprite
Camera Events ( Phaser.Cameras.Scene2D.Events )
Emitter: individual camera instance (e.g. this.cameras.main ). Each camera effect has a START and COMPLETE pair.
DESTROY 'cameradestroy' FADE IN START 'camerafadeinstart' FADE IN COMPLETE 'camerafadeincomplete' FADE OUT START 'camerafadeoutstart' FADE OUT COMPLETE 'camerafadeoutcomplete' FLASH START 'cameraflashstart' FLASH COMPLETE 'cameraflashcomplete' PAN START 'camerapanstart' PAN COMPLETE 'camerapancomplete' ROTATE START 'camerarotatestart' ROTATE COMPLETE 'camerarotatecomplete' SHAKE START 'camerashakestart' SHAKE COMPLETE 'camerashakecomplete' ZOOM START 'camerazoomstart' ZOOM COMPLETE 'camerazoomcomplete' FOLLOW UPDATE 'followupdate' PRE RENDER 'prerender' POST RENDER 'postrender'
Sound Events ( Phaser.Sound.Events )
Emitter: individual sound instances or this.sound (SoundManager)
Per sound instance events:
PLAY 'play' PAUSE 'pause' RESUME 'resume' STOP 'stop' COMPLETE 'complete' LOOP 'loop' LOOPED 'looped' SEEK 'seek' MUTE 'mute' VOLUME 'volume' RATE 'rate' DETUNE 'detune' PAN 'pan' DECODED 'decoded' DESTROY 'destroy'
SoundManager level events (on this.sound ):
GLOBAL MUTE 'mute' GLOBAL VOLUME 'volume' GLOBAL RATE 'rate' GLOBAL DETUNE 'detune' PAUSE ALL 'pauseall' RESUME ALL 'resumeall' STOP ALL 'stopall' DECODED ALL 'decodedall' UNLOCKED 'unlocked'
Tween Events ( Phaser.Tweens.Events )
Emitter: individual tween instances
Constant String When
TWEEN ACTIVE 'active' Tween becomes active
TWEEN START 'start' Tween starts first play
TWEEN UPDATE 'update' Tween updates a value
TWEEN YOYO 'yoyo' Tween yoyos (reverses direction)
TWEEN REPEAT 'repeat' Tween repeats
TWEEN LOOP 'loop' Tween loops
TWEEN PAUSE 'pause' Tween paused
TWEEN RESUME 'resume' Tween resumed
TWEEN COMPLETE 'complete' Tween finishes
TWEEN STOP 'stop' Tween stopped manually
Arcade Physics Events ( Phaser.Physics.Arcade.Events )
Emitter: this.physics.world
Constant String When
COLLIDE 'collide' Two bodies collide
OVERLAP 'overlap' Two bodies overlap
TILE COLLIDE 'tilecollide' Body collides with a tile
TILE OVERLAP 'tileoverlap' Body overlaps with a tile
WORLD BOUNDS 'worldbounds' Body hits world boundary
WORLD STEP 'worldstep' Physics world completes a step
PAUSE 'pause' Physics world paused
RESUME 'resume' Physics world resumed
Texture Events ( Phaser.Textures.Events )
Emitter: this.textures (TextureManager)
Constant String When
ADD 'addtexture' Any texture added
ADD KEY 'addtexture ' Specific texture added (append key)
REMOVE 'removetexture' Any texture removed
REMOVE KEY 'removetexture ' Specific texture removed (append key)
LOAD 'onload' Texture source loaded
ERROR 'onerror' Texture source load error
READY 'ready' Texture manager ready
GameObject Events ( Phaser.GameObjects.Events )
Emitter: individual GameObjects
Constant String When
ADDED TO SCENE 'addedtoscene' GameObject added to a scene
REMOVED FROM SCE