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

Methods

(static) getScene() → {Scene|undefined}

Get the current scene

Returns:
Type: 
Scene | undefined

(static) setScene(sceneopt)

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
Parameters:
NameTypeAttributesDescription
sceneScene<optional>

The scene to enter

Type Definitions

Scene

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

Type:
  • Object
Properties
NameTypeAttributesDescription
enterfunction<optional>

Called when the scene starts, after the old one left and the objects were destroyed

leavefunction<optional>

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

updatefunction<optional>

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

renderfunction<optional>

Called before gameRender, to draw under the objects

renderPostfunction<optional>

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