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
- Source
Methods
(static) getScene() → {Scene|undefined}
Get the current scene
- Source
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:
| Name | Type | Attributes | Description |
|---|---|---|---|
scene | Scene | <optional> | The scene to enter |
- Source
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:
Properties- Object
| Name | Type | Attributes | Description |
|---|---|---|---|
enter | function | <optional> | Called when the scene starts, after the old one left and the objects were destroyed |
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 |
- Source