World#alignTo()

alignTo(parent, position, offsetX, offsetY) → {Phaser.Group}

Aligns this Group to the side of another Game Object, or Rectangle, known as the
'parent', in one of 11 possible positions.

The parent must be a Game Object, or Phaser.Rectangle object. This can include properties
such as World.bounds or Camera.view, for aligning Groups within the world
and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText,
TileSprites or Buttons.

Please note that aligning a Group to another Game Object does not make it a child of
the parent. It simply modifies its position coordinates so it aligns with it.

The position constants you can use are:

Phaser.TOP_LEFT (default), Phaser.TOP_CENTER, Phaser.TOP_RIGHT, Phaser.LEFT_TOP,
Phaser.LEFT_CENTER, Phaser.LEFT_BOTTOM, Phaser.RIGHT_TOP, Phaser.RIGHT_CENTER,
Phaser.RIGHT_BOTTOM, Phaser.BOTTOM_LEFT, Phaser.BOTTOM_CENTER
and Phaser.BOTTOM_RIGHT.

Groups are placed in such a way that their bounds align with the
parent, taking into consideration rotation and scale of the children.
This allows you to neatly align Groups, irrespective of their position value.

The optional offsetX and offsetY arguments allow you to apply extra spacing to the final
aligned position of the Group. For example:

group.alignTo(background, Phaser.BOTTOM_RIGHT, -20, -20)

Would align the group to the bottom-right, but moved 20 pixels in from the corner.
Think of the offsets as applying an adjustment to the parents bounds before the alignment takes place.
So providing a negative offset will 'shrink' the parent bounds by that amount, and providing a positive
one expands it.

Parameters
Name Type Argument Default Description
parent Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite

The Game Object or Rectangle with which to align this Group to. Can also include properties such as World.bounds or Camera.view.

position integer <optional>

The position constant. One of Phaser.TOP_LEFT, Phaser.TOP_CENTER, Phaser.TOP_RIGHT, Phaser.LEFT_TOP, Phaser.LEFT_CENTER, Phaser.LEFT_BOTTOM, Phaser.RIGHT_TOP, Phaser.RIGHT_CENTER, Phaser.RIGHT_BOTTOM, Phaser.BOTTOM_LEFT, Phaser.BOTTOM_CENTER or Phaser.BOTTOM_RIGHT.

offsetX integer <optional>
0

A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.

offsetY integer <optional>
0

A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.

Returns

This Group.

Inherited From
Source code: core/Group.js (Line 2915)
doc_phaser
2017-02-14 11:20:29
Comments
Leave a Comment

Please login to continue.