top : number

Public Methods

alignIn(container, position, offsetX, offsetY) → {Object}

Aligns this Game Object within another Game Object, or Rectangle, known as the'container', to one of 9 possible positions.

The container must be a Game Object, or Phaser.Rectangle object. This can include propertiessuch as World.bounds or Camera.view, for aligning Game Objects within the worldand camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText,TileSprites or Buttons.

Please note that aligning a Sprite to another Game Object does not make it a child ofthe container. It simply modifies its position coordinates so it aligns with it.

The Game Objects are placed in such a way that their bounds align with thecontainer, taking into consideration rotation, scale and the anchor property.This allows you to neatly align Game Objects, irrespective of their position value.

The optional offsetX and offsetY arguments allow you to apply extra spacing to the finalaligned position of the Game Object. For example:

sprite.alignIn(background, Phaser.BOTTOM_RIGHT, -20, -20)

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

Returns

alignTo(parent, position, offsetX, offsetY) → {Object}

Aligns this Game Object 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 propertiessuch as World.bounds or Camera.view, for aligning Game Objects within the worldand camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText,TileSprites or Buttons.

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

The Game Objects are placed in such a way that their bounds align with theparent, taking into consideration rotation, scale and the anchor property.This allows you to neatly align Game Objects, irrespective of their position value.

The optional offsetX and offsetY arguments allow you to apply extra spacing to the finalaligned position of the Game Object. For example:

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

Would align the sprite 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 positiveone expands it.