GameScene
Extends: GameEntity
A GameScene is a GameEntity that represents one distinct state of your game - a title screen, a menu, a level. Register scenes with Game.defineScene() and switch between them with Game.changeScene(). Only one GameScene is current at a time, and it gets the same per-frame hooks (onUpdate, onInput, ...) as any other entity.
Every scene change destroys all non-persistent entities, including "changing" to the current scene again with Game.resetScene(). When changing to a different scene, the outgoing scene's own drawables (anything added with addDrawable()/addImage()/etc. directly on the scene) are removed too, by this class's default onChangeScene(). On a resetScene() the scene's own drawables are left in place, since onCreate() runs again immediately and typically re-adds everything.
To keep some or all of a scene's own drawables across a change:
- set
persistDrawablesAcrossSceneChange = trueto keep all of them, or - override
onChangeScene()with your own cleanup. An override replaces the default cleanup unless it callssuper.onChangeScene(newScene).
Properties
persistDrawablesAcrossSceneChange(boolean) — Whether this scene's own directly-added drawables survive a change to a different
Constructor
new GameScene(
gameEngine: Game,
args?: roAssociativeArray,
): GameSceneParameters
gameEngine(Game)args(roAssociativeArray, optional, default: "{}")
Instance Methods
onChangeScene(newScene: GameScene): void
Parameters
newScene(GameScene)
Returns
void