Class: Layer

Layer

new gdjs.Layer(layerData, runtimeScene)

Represents a layer of a scene, used to display objects.

Viewports and multiple cameras are not supported.

Name Type Description
layerData Object

The data used to initialize the layer

runtimeScene gdjs.RuntimeScene

The scene in which the layer is used

Methods

convertCoords(x, y, cameraId)

Convert a point from the canvas coordinates (For example, the mouse position) to the "world" coordinates.

TODO: Update this method to store the result in a static array

Name Type Description
x number

The x position, in canvas coordinates.

y number

The y position, in canvas coordinates.

cameraId number optional

The camera number. Currently ignored.

enableEffect(name, enable)

Enable or disable an effect.

Name Type Description
name string

The name of the effect to enable or disable.

enable boolean

true to enable, false to disable

getCameraHeight(cameraId){number}

Get the camera height (which can be different than the game resolution height if the camera is zoomed).

Name Type Description
cameraId number optional

The camera number. Currently ignored.

Returns:
Type Description
number The height of the camera

getCameraRotation(cameraId){number}

Get the rotation of the camera, expressed in degrees.

Name Type Description
cameraId number optional

The camera number. Currently ignored.

Returns:
Type Description
number The rotation, in degrees.

getCameraWidth(cameraId){number}

Get the camera width (which can be different than the game resolution width if the camera is zoomed).

Name Type Description
cameraId number optional

The camera number. Currently ignored.

Returns:
Type Description
number The width of the camera

getCameraX(cameraId)

Change the camera center X position.

Name Type Description
cameraId number optional

The camera number. Currently ignored.

Returns:
The x position of the camera

getCameraY(cameraId)

Change the camera center Y position.

Name Type Description
cameraId number optional

The camera number. Currently ignored.

Returns:
The y position of the camera

getCameraZoom(cameraId){number}

Get the zoom of a camera.

Name Type Description
cameraId number optional

The camera number. Currently ignored.

Returns:
Type Description
number The zoom.

getElapsedTime()

Return the time elapsed since the last frame, in milliseconds, for objects on the layer.

getName(){String}

Get the name of the layer

Returns:
Type Description
String The name of the layer

getRuntimeScene(){gdjs.RuntimeScene}

Returns the scene the layer belongs to

Returns:
Type Description
gdjs.RuntimeScene the scene the layer belongs to

getTimeScale()

Get the time scale for the objects on the layer.

isEffectEnabled(name){boolean}

Check if an effect is enabled

Name Type Description
name string

The name of the effect

Returns:
Type Description
boolean true if the effect is enabled, false otherwise.

isVisible()

Check if the layer is visible.

Returns:
true if the layer is visible.

onGameResolutionResized()

Called by the RuntimeScene whenever the game resolution size is changed. Updates the layer width/height and position.

setCameraRotation(rotation, cameraId)

Set the rotation of the camera, expressed in degrees. The rotation is made around the camera center.

Name Type Description
rotation number

The new rotation, in degrees.

cameraId number optional

The camera number. Currently ignored.

setCameraX(x, cameraId)

Set the camera center X position.

Name Type Description
x number

The new x position

cameraId number optional

The camera number. Currently ignored.

setCameraY(y, cameraId)

Set the camera center Y position.

Name Type Description
y number

The new y position

cameraId number optional

The camera number. Currently ignored.

setCameraZoom(newZoom, cameraId)

Set the zoom of a camera.

Name Type Description
newZoom number

The new zoom. Must be superior to 0. 1 is the default zoom.

cameraId number optional

The camera number. Currently ignored.

setEffectBooleanParameter(name, parameterName, value)

Change an effect parameter value (for parameters that are booleans).

Name Type Description
name string

The name of the effect to update.

parameterName string

The name of the parameter to update.

value boolean

The new value (boolean).

setEffectDoubleParameter(name, parameterName, value)

Change an effect parameter value (for parameters that are numbers).

Name Type Description
name string

The name of the effect to update.

parameterName string

The name of the parameter to update.

value number

The new value (number).

setEffectStringParameter(name, parameterName, value)

Change an effect parameter value (for parameters that are strings).

Name Type Description
name string

The name of the effect to update.

parameterName string

The name of the parameter to update.

value string

The new value (string).

setTimeScale(timeScale)

Set the time scale for the objects on the layer: time will be slower if time scale is < 1, faster if > 1.

Name Type Description
timeScale number

The new time scale (must be positive).

show(enable)

Show (or hide) the layer.

Name Type Description
enable boolean

true to show the layer, false to hide it.

update(runtimeScene)

Called at each frame, after events are run and before rendering.

Name Type Description
runtimeScene gdjs.RuntimeScene

The scene the layer belongs to.