WorldInfo

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

The WorldInfo class represents the state of an instance in the "world" (i.e. the Layout it is in). This includes information like its position, size, angle, Z order, layer and so on.

Only "world" type plugin instances have an associated WorldInfo. It is typically obtained by using the Instance GetWorldInfo() method.

Modifying geometric properties

For performance reasons, changing the X, Y, angle, width, height or origin does not update the corresponding bounding box, which is stored separately. If any of these properties are changed, you must call SetBboxChanged() afterwards to ensure the runtime re-calculates the bounding box.

Methods

GetInstance()

Return the associated Instance that this WorldInfo represents state for.

SetX(x)

SetY(y)

SetXY(x, y)

GetX()

GetY()

Set and get the position of the instance in layout co-ordinates.

OffsetX(x)

OffsetY(y)

OffsetXY(x, y)

Add to the X and Y components of the instance's position. For example OffsetX(5) is equivalent to SetX(GetX() + 5).

SetWidth(w)

SetHeight(h)

SetSize(w, h)

GetWidth()

GetHeight()

Set and get the width and height of the instance in layout co-ordinates.

SetAngle(a)

GetAngle()

Set and get the angle of the instance in radians. Use C3.toDegrees() and C3.toRadians() to convert from degrees to radians.

SetOriginX(x)

SetOriginY(y)

GetOriginX()

GetOriginY()

Set and get the origin of the instance as a normalized position in the [0,1] range, i.e. 0.5 is the middle.

SetBboxChanged()

Mark the instance's bounding box as having been changed. Call this after altering the position, size, angle or origin of the instance.

GetBoundingBox()

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

GetBoundingQuad()

Return a C3.Quad representing the bounding quad of the instance in layout co-ordinates, which is essentially the rotated bounding box.

SetOpacity(o)

GetOpacity()

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

SetUnpremultipliedColor(c)

Set the RGB components of the instance color. This applies a built-in color multiply effect which appears like a tint. As with opacity, color values are in the [0,1] range. The default is RGB 1,1,1 (white) which means the instance appears with normal colors. Pass a C3.Color as the parameter. The runtime internally uses premultiplied alpha for best rendering quality; in this method the RGB values do not need to be premultiplied with the alpha (opacity) value, since it will apply the premultiplication for you.

GetUnpremultipliedColor()

GetPremultipliedColor()

Get the instance color as a read-only C3.Color, either without or with premultiplied alpha (respectively). The instance color includes the opacity in the alpha channel.

HasDefaultColor()

Returns true if the instance color RGBA value equals (1,1,1,1), else false.

SetBlendMode(bm)

GetBlendMode()

Set and get the instance 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.

GetLayer()

Get the Layer the instance is currently on.

GetLayout()

Get the Layout the instance currently belongs to.

SetVisible(v)

IsVisible()

Set and get the visible state for the instance. This is a boolean that hides the instance when set to false.

SetCollisionEnabled(e)

IsCollisionEnabled()

Set and get a boolean indicating whether collisions are enabled for this instance.

ContainsPoint(x, y)

Test if a point in layout co-ordinates intersects this instance, respecting its collision polygon and collisions enabled flag.