LittleJS 1.28.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:56

Get the current scene

setScene(scene)sceneSystem.js:32

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
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