Skip to content

Instantly share code, notes, and snippets.

@samme
Last active August 2, 2023 16:26
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save samme/01a33324a427f626254c1a4da7f9b6a3 to your computer and use it in GitHub Desktop.
Save samme/01a33324a427f626254c1a4da7f9b6a3 to your computer and use it in GitHub Desktop.
Phaser 3 Scenes Summary

Scene control

Calls without a key argument

These affect the calling scene only.

Example:

this.scene.start()
method calling scene notes
pause pause
remove destroy Queued during scene processing
restart shutdown?, start Shutdown first only if RUNNING or PAUSED.
resume resume
sleep sleep
start shutdown?, start Shutdown first only if RUNNING or PAUSED.
stop shutdown
wake wake

remove() is queued while the Scene Manager is updating or rendering, or run immediately otherwise.

All other operations are queued always.

start() and restart() are identical when called without a key argument.

Calls with a key argument

These affect the target scene and may affect the calling scene.

Example:

this.scene.start('target')
method calling scene target scene notes
launch shutdown?, start Target scene is shutdown first only if RUNNING or PAUSED. If the calling scene is also the target, nothing happens
pause pause
remove destroy Queued during scene processing
resume resume
run shutdown?, start / wake / resume Target scene is shutdown first only if RUNNING
sleep sleep
start shutdown shutdown?, start Target scene is shutdown first only if RUNNING or PAUSED
stop shutdown
switch sleep shutdown?, start / wake Target scene is shutdown first only if RUNNING or PAUSED
wake wake

remove() is queued while the Scene Manager is updating or rendering, or run immediately otherwise.

All other operations are queued always.

restart() never takes a key argument. Use launch('target') instead.

Scene Systems

Scene operations change a scene's state and trigger certain events.

Within a scene, you can listen to these events from this.events.

active means a scene is updating its objects and plugins.

visible means a scene is rendering its objects and plugins.

method status identity active visible events
init INIT boot
start START yes yes start, ready
pause PAUSED isPaused() no pause
resume RUNNING isActive() yes resume
sleep SLEEPING isSleeping() no no sleep
wake RUNNING isActive() yes yes wake
shutdown SHUTDOWN no no shutdown
destroy DESTROYED no no destroy

Scene Flow

Table shows: SCENE STATUS, scene events, scene methods

INIT START LOADING CREATING RUNNING PAUSED SLEEPING SHUTDOWN DESTROYED
boot
start (resume/wake) pause sleep shutdown destroy
ready
init
create
preupdate preupdate
update update
update
postupdate postupdate
prerender prerender prerender
render render render
  • resume is emitted only for PAUSED → RUNNING.
  • wake is emitted only for SLEEPING → RUNNING.

References

@samme
Copy link
Author

samme commented Jul 23, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment