Crafty.scene

Events

SceneChange [Data: { oldScene:String, newScene:String }]
when a scene is played

public void Crafty.scene(String sceneName, Function init[, Function uninit])

sceneName
Name of the scene to add
init
Function to execute when scene is played
uninit
Function to execute before next scene is played, after entities with 2D are destroyed

public void Crafty.scene(String sceneName)

sceneName
Name of scene to play

Method to create scenes on the stage. Pass an ID and function to register a scene.

To play a scene, just pass the ID. When a scene is played, all entities with the 2D component on the stage are destroyed.

If you want some entities to persist over scenes (as in not be destroyed) simply add the component Persist.

Example

Crafty.scene("loading", function() {});

Crafty.scene("loading", function() {}, function() {});

Crafty.scene("loading");