-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
AlignTo.js
47 lines (40 loc) · 1.54 KB
/
AlignTo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* @author samme
* @copyright 2013-2024 Phaser Studio Inc.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var QuickSet = require('../display/align/to/QuickSet');
/**
* Takes an array of Game Objects and aligns them next to each other.
*
* The alignment position is controlled by the `position` parameter, which should be one
* of the Phaser.Display.Align constants, such as `Phaser.Display.Align.TOP_LEFT`,
* `Phaser.Display.Align.TOP_CENTER`, etc.
*
* The first item isn't moved. The second item is aligned next to the first,
* then the third next to the second, and so on.
*
* @function Phaser.Actions.AlignTo
* @since 3.22.0
*
* @generic {Phaser.GameObjects.GameObject[]} G - [items,$return]
*
* @param {(array|Phaser.GameObjects.GameObject[])} items - The array of items to be updated by this action.
* @param {number} position - The position to align the items with. This is an align constant, such as `Phaser.Display.Align.LEFT_CENTER`.
* @param {number} [offsetX=0] - Optional horizontal offset from the position.
* @param {number} [offsetY=0] - Optional vertical offset from the position.
*
* @return {(array|Phaser.GameObjects.GameObject[])} The array of objects that were passed to this Action.
*/
var AlignTo = function (items, position, offsetX, offsetY)
{
var target = items[0];
for (var i = 1; i < items.length; i++)
{
var item = items[i];
QuickSet(item, target, position, offsetX, offsetY);
target = item;
}
return items;
};
module.exports = AlignTo;