LittleJS 1.31.0

SceneSystem

LittleJS Scene System Plugin

  • A game's states, like a title, the game and game over, as scene objects
  • setScene leaves the current scene, destroys the objects and enters the next
  • Objects with the persistent flag set outlive every switch
  • Pause is the engine's paused flag, a scene's update stops with gameUpdate

Functions

Typedefs

Functions

getScene() → Scene|undefinedsceneSystem.js:94

Get the current scene

setScene(scene)sceneSystem.js:40

Leave the current scene, destroy every object that is not persistent, and enter the next scene

  • Setting the current scene again restarts it, and no scene leaves the game with none
  • The switch happens at once, it can be called from anywhere but a scene's leave; from a Box2D contact callback it happens once the physics step is done, since Box2D can not make bodies during one, and several calls in one step, as two fixtures touching spikes make, switch once, to the scene the last one asked for
  • Called while a switch destroys the old scene's objects, from an object's destroy or a Box2D endContact, it is dropped with a warning in debug builds, so the scene the switch was asked for wins
  • UI objects and tweens are not objects of the scene and stay, uiSystem.destroyObjects() and tweenStopAll() end them
scene Scene optional

The scene to enter

Typedefs

Scene : ObjectsceneSystem.js:14

A scene, any object with the hooks it needs, each optional and called as a method so this is the scene

enter function optional

Called when the scene starts, after the old one left and the objects were destroyed; it is not awaited, so setup done once, like await box2dInit() and new plugins, goes in gameInit before the first setScene

leave function optional

Called before the next scene starts, while the scene is current and its objects are still there

update function optional

Called each update after gameUpdate, not while paused or at time scale 0

render function optional

Called before gameRender, to draw under the objects

renderPost function optional

Called after gameRenderPost, to draw over the game, while paused too; plugins made after the first setScene draw over it