gameify. Scene

Creates a scene in the game. (Eg. a menu or level)

Constructor

new Scene(screen)

Parameters:
NameTypeDescription
screengameify.Screen

The Screen the Scene should draw to.

Example
// Create a Screen that is 600 by 400 and centered
let myScreen = new gameify.Screen(document.querySelector("#my-canvas"), 600, 400);
myScreen.center();

// Create a Scene and give it update and draw functions
let mainMenu = new gameify.Scene(myScreen);
mainMenu.onUpdate((delta) => {
    // code ...
});
mainMenu.onDraw(() => {
    // code ...
});

// Start the game
myScreen.setScene(mainMenu);
myScreen.startGame();

Members

locked

If the scene is locked

parent

The parent Screen

Methods

draw()

Draw the scene. This is done automatically, you usually shouldn't have to use it yourself.

fromJSON(data, ref) → {gameify.Scene}

Creates a object from JSON data

Parameters:
NameTypeDescription
dataObject | Array

Serialized object data (from object.toJSON)

reffunction

A function that returns a name for other objects, so they can be restored later

Returns:
Type: 
gameify.Scene

lock(textopt)

Lock the scene, meaning you cannot switch to another scene until it is unlocked with scene.unlock()

Parameters:
NameTypeAttributesDescription
textString<optional>

A helpful message to display when you try to switch scenes

onDraw(callback)

Set the draw function for this scene

Parameters:
NameTypeDescription
callbackfunction

(package) onLoad(parent)

Run when the scene is set as a Screen's active scene

Parameters:
NameTypeDescription
parentgameify.Screen

onSceneHidden(callback)

Defined a callback to be run when the scene is hidden (switched away from)

Parameters:
NameTypeDescription
callbackfunction

onSceneShown(callback)

Defined a callback to be run when the scene is shown (switched to)

Parameters:
NameTypeDescription
callbackfunction

(package) onUnload()

Run when the scene is set as inactive / replaced by another scene

onUpdate(callback)

Set the update function for this scene

Parameters:
NameTypeDescription
callbackfunction

The function that is called every update. Optionally, you can include a delta argument for physics and movement calculations.

toJSON(keyopt, ref) → {Object}

Convert the object to JSON

Parameters:
NameTypeAttributesDescription
keystring<optional>

Key object is stored under (unused, here for consistency with e.g. Date.toJSON, etc.)

reffunction

A function that returns a name for other objects, so they can be restored later

Returns:
Type: 
Object

unlock()

Unlock the scene, meaning you can now switch to another scene. Scenes are unlocked by default

update()

Update the scene