Constructor
new Scene(screen)
| Name | Type | Description |
|---|---|---|
screen | gameify. | The Screen the Scene should draw to. |
// 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
| Name | Type | Description |
|---|---|---|
data | Object | | Serialized object data (from object.toJSON) |
ref | function | A function that returns a name for other objects, so they can be restored later |
- Type:
- gameify.
Scene
lock(textopt)
Lock the scene, meaning you cannot switch to another scene until it is unlocked with scene.unlock()
| Name | Type | Attributes | Description |
|---|---|---|---|
text | String | <optional> | A helpful message to display when you try to switch scenes |
onDraw(callback)
Set the draw function for this scene
| Name | Type | Description |
|---|---|---|
callback | function |
(package) onLoad(parent)
Run when the scene is set as a Screen's active scene
| Name | Type | Description |
|---|---|---|
parent | gameify. |
onSceneHidden(callback)
Defined a callback to be run when the scene is hidden (switched away from)
| Name | Type | Description |
|---|---|---|
callback | function |
onSceneShown(callback)
Defined a callback to be run when the scene is shown (switched to)
| Name | Type | Description |
|---|---|---|
callback | function |
(package) onUnload()
Run when the scene is set as inactive / replaced by another scene
onUpdate(callback)
Set the update function for this scene
| Name | Type | Description |
|---|---|---|
callback | function | 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
| Name | Type | Attributes | Description |
|---|---|---|---|
key | string | <optional> | Key object is stored under (unused, here for consistency with e.g. Date.toJSON, etc.) |
ref | function | A function that returns a name for other objects, so they can be restored later |
- Type:
- Object
unlock()
Unlock the scene, meaning you can now switch to another scene. Scenes are unlocked by default
update()
Update the scene