Layer

Ashley's avatar
Medal
Construct Team Founder
Published 16 May, 2018
393 words
~2-3 mins

The Layer class represents a layer in the runtime.

Methods

GetLayout()

Return the Layout the layer belongs to.

GetRuntime()

Return the Runtime for this layer.

GetName()

Return a string of the name of the layer.

GetIndex()

Return the zero-based index of this layer on its layout.

SetVisible(v)

IsVisible()

Set or get a boolean determining whether the layer is visible.

GetViewport()

Return a C3.Rect representing the axis-aligned bounding box of the visible area of the layer in layout co-ordinates.

SetOpacity(o)

GetOpacity()

Set and get the opacity of the layer in the [0,1] range. 0 is fully transparent and 1 is opaque. This changes the alpha component of the layer color.

SetOwnScale(s)

GetOwnScale()

Set and get the layer's scale as a factor.

GetRenderScale()

Get the scale the layer is rendered at. This is the scale relevant to draw calls.

GetDisplayScale()

Get the scale the layer is rendered at. This is the scale relevant for translating co-ordinates from the canvas/window to the layer.

GetNormalScale()

Get the scale of the layer only using its own scale, the layout scale, and the scale rate.

SetScaleRate(r)

GetScaleRate()

Set and get the scale rate of the layer as a multiplier.

SetParallaxX(px)

SetParallaxY(py)

SetParallax(px, py)

GetParallaxX()

GetParallaxY()

Set and get the X and Y parallax ratios for the layer, as multipliers.

SetAngle(a)

GetOwnAngle()

Set and get the layer's angle in radians. Use C3.toDegrees() and C3.toRadians() to convert from degrees to radians.

GetAngle()

Get the layer's display angle in radians. This is also affected by the layout angle.

GetBackgroundColor()

Return a C3.Color representing the layer background color. Only the RGB components are used.

SetTransparent(t)

IsTransparent()

Set and get a boolean indicating if the layer background is transparent.

SetBlendMode(bm)

GetBlendMode()

Set and get the layer blend mode, as an index in to the dropdown list used in Construct's Blend mode property. E.g. 0 is "normal", 1 is "additive", etc.

MoveInstanceAdjacent(inst, otherInst, isAfter)

Move the Instance inst adjacent to otherInst in the Z order. If isAfter is true it moves inst just after (above) otherInst in the Z order; otherwise it moves inst just before (below).

CanvasCssToLayer(x, y)

LayerToCanvasCss(x, y)

Translate CSS pixel co-ordinates on the canvas to layout co-ordinates on the layer, and vice versa. Returns [x, y].

DrawSurfaceToLayer(x, y)

LayerToDrawSurface(x, y)

Translate device pixels on the rendered surface to layout co-ordinates on the layer, and vice versa. Returns [x, y].