Scene
convergame.scene
changeScene(scene)
Description
The changeScene method simply changes the currently activate scene. Technically, it performs the following steps.
- Reset mouse and keyboard input controls, preventing mouse clicks and key presses transferring to the new scene.
- Change the engine's active scene to the passed object. This essentially tells the engine to call the passed scene's
updateandrendermethods. - Initialises the passed scene by calling its
initmethod, passing in an instance of the convergame engine object.
Parameters
| Parameter name | Type | Description |
|---|---|---|
scene | An instantiated scene object | The scene object you wish to change to |
Example
The following example is a splash scene. Upon pressing the left mouse button anywhere on the canvas, the scene is changed to the mainMenuScene.
This main menu scene is assumed to have been instantiated already, in the global scope.
function SplashScene()
{
var convergame;
this.update = function(time)
{
if (this.convergame.input.mouse.isLeftButtonPressed())
{
// Change scene to main menu
this.convergame.scene.changeScene(mainMenuScene);
}
};
this.render = function()
{
this.convergame.draw.blankCanvas('#111111');
this.convergame.draw.text(100, 100, '#ccc', 72, 'sans-serif', 'left', 'Click the left mouse button to change scene');
};
this.init = function(convergame)
{
this.convergame = convergame;
};
}
addPersistentScene(sceneObject)
Description
The addPersistentScene method adds an instantiated scene as a persistent scene. A persistent scene will have its update method ran before the main scene and its render method ran after the main scene.
Persistent scenes can be useful for creating background processing that is independent of a particular main scene. They can also be useful for creating rendering that overlays the rendering of the main scene, such as a HUD, score or toolbar.
The persistent scene will remain active until it is removed using the removePersistentScene method.
Parameters
| Parameter name | Type | Description |
|---|---|---|
sceneObject | An instantiated scene object | The scene object you wish to add as a persistent scene |
Example
The following example instantiates and adds a persistent scene called ScoreDisplayPS.
var scoreDisplayPS = new ScoreDisplayPS();
convergame.scene.addPersistentScene(scoreDisplayPS);
removePersistentScene(sceneObject)
Description
The removePersistentScene method will remove a previously added scene from the list of persistent scenes that are processed.
Parameters
| Parameter name | Type | Description |
|---|---|---|
sceneObject | An instantiated scene object | The scene object you wish to remove from the list of active persistent scenes. This must be an scene object you have previously added using the addPersistentScene method |
Example
The example below removes a persistent scene called ScoreDisplayPS. This scene is assumed to have been previously added using the addPersistentScene method.
convergame.scene.removePersistentScene(scoreDisplayPS);
Updated less than a minute ago
