MCPcopy
hub / github.com/phaserjs/phaser / GridAlign

Function GridAlign

src/actions/GridAlign.js:40–122  ·  view source on GitHub ↗
(items, options)

Source from the content-addressed store, hash-verified

38 * @return {(array|Phaser.GameObjects.GameObject[])} The array of objects that were passed to this Action.
39 */
40var GridAlign = function (items, options)
41{
42 if (options === undefined) { options = {}; }
43
44 var widthSet = options.hasOwnProperty('width');
45 var heightSet = options.hasOwnProperty('height');
46
47 var width = GetFastValue(options, 'width', -1);
48 var height = GetFastValue(options, 'height', -1);
49
50 var cellWidth = GetFastValue(options, 'cellWidth', 1);
51 var cellHeight = GetFastValue(options, 'cellHeight', cellWidth);
52
53 var position = GetFastValue(options, 'position', CONST.TOP_LEFT);
54 var x = GetFastValue(options, 'x', 0);
55 var y = GetFastValue(options, 'y', 0);
56
57 var cx = 0;
58 var cy = 0;
59 var w = (width * cellWidth);
60 var h = (height * cellHeight);
61
62 tempZone.setPosition(x, y);
63 tempZone.setSize(cellWidth, cellHeight);
64
65 for (var i = 0; i < items.length; i++)
66 {
67 AlignIn(items[i], tempZone, position);
68
69 if (widthSet && width === -1)
70 {
71 // We keep laying them out horizontally until we've done them all
72 tempZone.x += cellWidth;
73 }
74 else if (heightSet && height === -1)
75 {
76 // We keep laying them out vertically until we've done them all
77 tempZone.y += cellHeight;
78 }
79 else if (heightSet && !widthSet)
80 {
81 // We keep laying them out until we hit the column limit
82 cy += cellHeight;
83 tempZone.y += cellHeight;
84
85 if (cy === h)
86 {
87 cy = 0;
88 cx += cellWidth;
89 tempZone.y = y;
90 tempZone.x += cellWidth;
91
92 if (cx === w)
93 {
94 // We've hit the column limit, so return, even if there are items left
95 break;
96 }
97 }

Callers 1

GridAlign.test.jsFile · 0.85

Calls 3

GetFastValueFunction · 0.85
setPositionMethod · 0.80
setSizeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…