Anchor behavior

The Anchor behavior is useful for automatically positioning objects relative to the window size. This is useful for supporting multiple screen sizes. For more information on features to support multiple screen sizes, see the tutorial Supporting multiple screen sizes.

Objects using the Anchor behavior should also be placed on a layer with its parallax set to 0, 0. Otherwise as the game scrolls the objects may "lag" behind the screen.

Positioning objects relative to the window size

In the top-left of the Layout View, a dotted outline represents the default size of the game window. Anchored objects should be positioned inside the dotted window area, as shown below.

Positioning some objects with the Anchor behavior.
Now if the window is resized during preview, the objects maintain their relative positions, as shown below:

Anchor responding to window size.
This is useful for interface elements like notifications and heads-up displays (HUDs).

Relative positioning

The Left edge and Top edge position the object relative to the window corners, without changing the object size. For example, if the Left edge is set to Window right, the object will always stay the same distance from the right edge of the window.

The Right edge and Bottom edge resize the object relative to the window corners. For example, if you want a Tiled Background to stretch wider as the window widens, set Right edge to Window right.

Anchor conditions, actions and expressions

The Anchor object has a single action:

Set enabled
Set whether the behavior is enabled or disabled. If disabled, the behavior will not alter the size or position of the object.

Tags: