Layer

Layer

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

Viewports and multiple cameras are not supported.

Constructor

new Layer(layerData, runtimeScene)

Parameters:
Name Type Description
layerData

The data used to initialize the layer

runtimeScene

The scene in which the layer is used

Source:

Methods

addEffect(effectData)

Add a new effect, or replace the one with the same name.

Parameters:
Name Type Description
effectData

The data of the effect to add.

Source:

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

Parameters:
Name Type Description
x

The x position, in canvas coordinates.

y

The y position, in canvas coordinates.

cameraId

The camera number. Currently ignored.

Source:

enableEffect(name, enable)

Enable or disable an effect.

Parameters:
Name Type Description
name

The name of the effect to enable or disable.

enable

true to enable, false to disable

Source:

followBaseLayer()

Change the position, rotation and scale (zoom) of the layer camera to be the same as the base layer camera.

Source:

getCameraHeight(cameraId)

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

Parameters:
Name Type Description
cameraId

The camera number. Currently ignored.

Returns:
Type Description

The height of the camera

Source:

getCameraRotation(cameraId)

Get the rotation of the camera, expressed in degrees.

Parameters:
Name Type Description
cameraId

The camera number. Currently ignored.

Returns:
Type Description

The rotation, in degrees.

Source:

getCameraWidth(cameraId)

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

Parameters:
Name Type Description
cameraId

The camera number. Currently ignored.

Returns:
Type Description

The width of the camera

Source:

getCameraX(cameraId)

Change the camera center X position.

Parameters:
Name Type Description
cameraId

The camera number. Currently ignored.

Returns:
Type Description

The x position of the camera

Source:

getCameraY(cameraId)

Change the camera center Y position.

Parameters:
Name Type Description
cameraId

The camera number. Currently ignored.

Returns:
Type Description

The y position of the camera

Source:

getCameraZoom(cameraId)

Get the zoom of a camera.

Parameters:
Name Type Description
cameraId

The camera number. Currently ignored.

Returns:
Type Description

The zoom.

Source:

getClearColor()

The clear color is defined in the format [r, g, b], with components in the range of 0 to 1.

Returns:
Type Description

the clear color of layer in the range of [0, 1].

Source:

getDefaultZOrder()

Get the default Z order to be attributed to objects created on this layer (usually from events generated code).

Source:

getElapsedTime()

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

Source:

getInitialEffectsData()

Return the initial effects data for the layer. Only to be used by renderers.

Deprecated:
  • Yes

Source:

getName()

Get the name of the layer

Returns:
Type Description

The name of the layer

Source:

getRuntimeScene()

Returns the scene the layer belongs to

Returns:
Type Description

the scene the layer belongs to

Source:

getTimeScale()

Get the time scale for the objects on the layer.

Source:

hasEffect(name)

Check if an effect exists on this layer

Parameters:
Name Type Description
name

The name of the effect

Returns:
Type Description

true if the effect exists, false otherwise.

Source:

isEffectEnabled(name)

Check if an effect is enabled

Parameters:
Name Type Description
name

The name of the effect

Returns:
Type Description

true if the effect is enabled, false otherwise.

Source:

isLightingLayer()

Return true if the layer is a lighting layer, false otherwise.

Returns:
Type Description

true if it is a lighting layer, false otherwise.

Source:

isVisible()

Check if the layer is visible.

Returns:
Type Description

true if the layer is visible.

Source:

onGameResolutionResized()

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

Source:

removeEffect(effectName)

Remove the effect with the specified name

Parameters:
Name Type Description
effectName

The name of the effect.

Source:

setCameraRotation(rotation, cameraId)

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

Parameters:
Name Type Description
rotation

The new rotation, in degrees.

cameraId

The camera number. Currently ignored.

Source:

setCameraX(x, cameraId)

Set the camera center X position.

Parameters:
Name Type Description
x

The new x position

cameraId

The camera number. Currently ignored.

Source:

setCameraY(y, cameraId)

Set the camera center Y position.

Parameters:
Name Type Description
y

The new y position

cameraId

The camera number. Currently ignored.

Source:

setCameraZoom(newZoom, cameraId)

Set the zoom of a camera.

Parameters:
Name Type Description
newZoom

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

cameraId

The camera number. Currently ignored.

Source:

setClearColor(r, g, b)

Set the clear color in format [r, g, b], with components in the range of 0 to 1.;

Parameters:
Name Type Description
r

Red color component in the range 0-255.

g

Green color component in the range 0-255.

b

Blue color component in the range 0-255.

Source:

setDefaultZOrder(defaultZOrder)

Set the default Z order to be attributed to objects created on this layer.

Parameters:
Name Type Description
defaultZOrder

The Z order to use when creating a new object from events.

Source:

setEffectBooleanParameter(name, parameterName, value)

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

Parameters:
Name Type Description
name

The name of the effect to update.

parameterName

The name of the parameter to update.

value

The new value (boolean).

Source:

setEffectDoubleParameter(name, parameterName, value)

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

Parameters:
Name Type Description
name

The name of the effect to update.

parameterName

The name of the parameter to update.

value

The new value (number).

Source:

setEffectStringParameter(name, parameterName, value)

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

Parameters:
Name Type Description
name

The name of the effect to update.

parameterName

The name of the parameter to update.

value

The new value (string).

Source:

setFollowBaseLayerCamera()

Set whether layer's camera follows base layer's camera or not.

Source:

setTimeScale(timeScale)

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

Parameters:
Name Type Description
timeScale

The new time scale (must be positive).

Source:

show(enable)

Show (or hide) the layer.

Parameters:
Name Type Description
enable

true to show the layer, false to hide it.

Source:

updatePreRender()

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

Source: