Layer script interface
The ILayer
script interface represents a layer on a layout.
Examples
See the Input event position example for a demonstration of using the layer cssPxToLayer()
method, which is useful when handling input events.
Layer APIs
- name
- A read-only string of the layer name.
- index
- A read-only number with the zero-based index of the layer on its layout. The bottom layer has an index of 0, with the index increasing upwards in Z order.
- layout
- The ILayout interface representing the layout this layer belongs to.
- parentLayer
- A reference to the layer's parent
ILayer
if it is a sub-layer, else null
if it is a top-level layer.
- *parentLayers()
- Iterates all the layer's parent layers, moving up towards the top of the hierarchy.
- *subLayers()
- Iterates the layer's own sub-layers in increasing Z order. This does not iterate any sub-layers at lower levels in the hierarchy.
- *allSubLayers()
- Iterates the layer's sub-layers and further sub-layers beneath those recursively, in increasing Z order.
- isInteractive
- A boolean indicating if the layer is interactive, allowing its content to respond to mouse and touch input.
- isSelfAndParentsInteractive
- A read-only boolean indicating if both this layer and all its parent layers are set to be interactive. If this is true the layer content will respond to mouse and touch input.
- isVisible
- A boolean indicating if the layer is visible. When invisible, the layer skips drawing entirely.
- isSelfAndParentsVisible
- A read-only boolean indicating if both this layer and all its parent layers are set to visible. If this is true the layer will be drawn.
- isTransparent
- A boolean indicating if the layer background is transparent. When transparent, the background color is ignored.
- backgroundColor
- Set or get the background color of a layer as an array with 3 elements specifying the red, green and blue components with values in the 0-1 range. Note this is ignored if the layer is transparent.
- isHTMLElementsLayer
- A boolean indicating if this layer acts as a HTML layer. For more information see HTML layers.
- scrollX
- scrollY
- scrollTo(x, y)
- getScrollPosition()
- restoreScrollPosition()
- Independently scroll a layer, regardless of where the layout is scrolled to. By default layers all follow the layout scroll position. Upon setting a layer's scroll position, the layer will stop following the layout scroll position, and remain scrolled at the position specified. The
restoreScrollPosition()
method reverts the layer to the default mode where it follows the layout scroll position. When not independently scrolling a layer, the scrollX
and scrollY
getters return the layout scroll position.
- parallaxX
- parallaxY
- Set or get the horizontal and vertical parallax rates of a layer.
- opacity
- The opacity of the layer, as a floating point number in the range [0, 1], where 0 is fully transparent and 1 is fully opaque. Note that changing the opacity to a value other than 1 will force the layer to render via its own texture.
- scale
- Set or get the layer scale, taking in to account its scale rate property.
- scaleRate
- Set or get the scale rate property of a layer, which affects how quickly it scales (if at all).
- angle
- Set or get the layer angle in radians.
- zElevation
- Set or get the Z elevation of the entire layer. By default the camera is at Z = 100, and looking down to Z = 0. The default Z elevation is 0. Increasing it will move the layer upwards (towards the camera) and decreasing it will move it downwards (away from the camera).
- getViewport()
- Return a DOMRect representing the bounds of the viewport on this layer in layout co-ordinates.
- isForceOwnTexture
- A boolean indicating the layer's Force own texture property. For more information see the property in the Layers manual entry.
- blendMode
- A string indicating the blend mode of the layer, controlling how it draws over the other layers behind it. This must be one of
"normal"
, "additive"
, "copy"
, "destination-over"
, "source-in"
, "destination-in"
, "source-out"
, "destination-out"
, "source-atop"
, "destination-atop"
.
- effects
- An array of IEffectInstance representing the effect parameters of the effects on this layer.
- cssPxToLayer(clientX, clientY, z = 0)
- layerToCssPx(layerX, layerY, z = 0)
- Convert between positions in CSS pixels, such as the
clientX/Y
properties of an input event, and layer co-ordinates within the project. An optional Z value can be provided to do the conversion taking in to account Z elevation to a certain height on the layer. This is useful for purposes like identifying what position in a layer was clicked in an input event, or positioning a HTML element in layer co-ordinates. Both methods return a pair of co-ordinates in the form [x, y]
.
- drawSurfaceToLayer(dsX, dsY, z = 0)
- layerToDrawSurface(layerX, layerY, z = 0)
- Convert between positions in layer co-ordinates and the draw surface in units of device pixels. An optional Z value can be provided to do the conversion taking in to account Z elevation to a certain height on the layer. Both methods return a pair of co-ordinates in the form
[x, y]
. These methods are intended for the Addon SDK and are for identifying the draw surface co-ordinates that correspond to an object.
- renderScale
- A read-only number with the render scale factor for this layer. This is intended for the Addon SDK where plugins need this value to render taking in to account Construct's scale factor.
Construct 3 Manual
Construct.net
2019-06-10
2024-06-24
You are here:
Search this manual:
This manual entry was last updated on 24 Jun, 2024 at 17:23