Description

Scene management. Structure of a scene :

canvas.Scene.new({
    name: "MyScene",
    materials: {
        images: {},
        sounds: {}
    },
    called: function(stage) {

    },
    preload: function(stage, pourcent, material) {

    },
    ready: function(stage) {

    },
    render: function(stage) {

    },
    exit: function(stage) {

    }
});

All parameters except "name" are optional. The "new" method created a scene but does not run. To execute:

canvas.Scene.call("MyScene");

The resources defined in "Materials" are loaded and regularly calls the method "preload" with the current percentage. When charging is completed, the method "ready" is executed only once. When the method "ready" is complete, the method "render" is called loop. If you call another scene, the method "exit" of the current scene is triggered "stage" is an object of type "Element". This is the main element of the scene containing all child elements to create.

Properties

model

(Obsolete) Model reference. The methods of this property are the same as scoket.io

Methods

call

Called a scene. Call the method "exit" of the current scene (if any) and changes of scene

exit

Leave a scene

isEnabled

Whether the scene is displayed

exitAll

Disables all scenes except one or more scene

exist

Return true if the scene exist

get

Get scene

getEnabled

Get activated scenes

pause

Pause the scene. method "render" is not called however, but the scene is refreshed (except the event "canvas: render")

togglePause

Pauses if the game is not paused, and vice versa. View pause method

getStage

Return the highest element

getCanvas

Get the canvas

zIndex

Change or get the index of the scene. The index used to define the superposition. By default, the first scene has index 0. If a scene is created at the same level, it will overlay the previous element and its index will be 1

createElement

Create an element

loadEvents

`(>= 1.3.0)` Support client/server events. If we connect before the opening of the scene, no need to call this method:

Discussion