Class: RuntimeScene

RuntimeScene

new gdjs.RuntimeScene(runtimeGame)

The runtimeScene object represents a scene being played and rendered in the browser in a canvas.

Name Type Description
runtimeGame gdjs.RuntimeGame

The game associated to this scene.

Methods

addObject(obj)

Add an object to the instances living on the scene.

Name Type Description
obj

The object to be added.

createNewUniqueId()

Create an identifier for a new object of the scene.

createObject(objectName){gdjs.RuntimeObject}

Create a new object from its name. The object is also added to the instances living on the scene ( No need to call RuntimeScene.addObject )

Name Type Description
objectName string

The name of the object to be created

Returns:
Type Description
gdjs.RuntimeObject The created object

createObjectsFrom(data, xPos, yPos)

Create objects from initial instances data ( for example, the initial instances of the scene or from an external layout ).

Name Type Description
data Object

The instances data

xPos number

The offset on X axis

yPos number

The offset on Y axis

getAdhocListOfAllInstances(){Array.<gdjs.RuntimeObject>}

Get a list of all gdjs.RuntimeObject living on the scene. You should not, normally, need this method at all. It's only to be used in exceptional use cases where you need to loop through all objects, and it won't be performant.

Returns:
Type Description
Array.<gdjs.RuntimeObject> The list of all runtime objects on the scnee

Get the runtimeGame associated to the RuntimeScene.

getInitialSharedDataForBehavior(name)

Get the data representing the initial shared data of the scene for the specified behavior.

Name Type Description
name string

The name of the behavior

Get the layer with the given name

Name Type Description
name string

The name of the layer

Returns:
Type Description
gdjs.Layer The layer, or the base layer if not found

Get the name of the scene.

getObjects(name){Array.<gdjs.RuntimeObject>}

Get all the instances of the object called name.

Name Type Description
name string

Name of the object for which the instances must be returned.

Returns:
Type Description
Array.<gdjs.RuntimeObject> The list of objects with the given name

getOnceTriggers()

Get the structure containing the triggers for "Trigger once" conditions.

getProfiler()

Get the profiler associated with the scene, or null if none.

getRenderer()

Get the renderer associated to the RuntimeScene.

getRequestedChange()

Return the value of the scene change that is requested.

getRequestedScene()

Return the name of the new scene to be launched.

See requestChange.

getSoundManager(){gdjs.SoundManager}

Shortcut to get the SoundManager of the game.

Returns:
Type Description
gdjs.SoundManager The gdjs.SoundManager of the game.

Get the TimeManager of the scene.

Returns:
Type Description
gdjs.TimeManager The gdjs.TimeManager of the scene.

getVariables()

Get the variables of the runtimeScene.

Returns:
The container holding the variables of the scene.

hasLayer(name)

Check if a layer exists

Name Type Description
name string

The name of the layer

loadFromScene(sceneData)

Load the runtime scene from the given scene.

Name Type Description
sceneData Object

An object containing the scene data.

See:

markObjectForDeletion(object)

Must be called whenever an object must be removed from the scene.

Name Type Description
object gdjs.RuntimeObject

The object to be removed.

onGameResolutionResized()

Should be called when the canvas where the scene is rendered has been resized. See gdjs.RuntimeGame.startGameLoop in particular.

Called when a scene is "paused", i.e it will be not be rendered again for some time, until it's resumed or unloaded.

Called when a scene is "resumed", i.e it will be rendered again on screen after having being paused.

Render the PIXI container associated to the runtimeScene.

renderAndStep(){boolean}

Step and render the scene.

Returns:
Type Description
boolean true if the game loop should continue, false if a scene change/push/pop or a game stop was requested.

requestChange(change, sceneName)

Request a scene change to be made. The change is handled externally (see gdjs.SceneStack) thanks to getRequestedChange and getRequestedScene methods.

Name Type Description
change number

One of gdjs.RuntimeScene.CONTINUE|PUSH_SCENE|POP_SCENE|REPLACE_SCENE|CLEAR_SCENES|STOP_GAME.

sceneName string

The name of the new scene to launch, if applicable.

sceneJustResumed(){boolean}

Check if the scene was just resumed. This is true during the first frame after the scene has been unpaused.

Returns:
Type Description
boolean true if the scene was just resumed

setBackgroundColor()

Change the background color

setEventsFunction(func)

Set the function called each time the scene is stepped. The function will be passed the runtimeScene as argument.

Note that this is already set up by the gdjs.RuntimeScene constructor and that you should not need to use this method.

Name Type Description
func function

The function to be called.

startProfiler(onProfilerStopped)

Start a new profiler to measures the time passed in sections of the engine in the scene.

Name Type Description
onProfilerStopped function

Function to be called when the profiler is stopped. Will be passed the profiler as argument.

stopProfiler()

Stop the profiler being run on the scene.

unloadScene()

Called before a scene is removed from the stack of scenes rendered on the screen.

updateObjectsForces()

Update the objects positions according to their forces