|
1 | | -var CONST = require('../../../utils/align/const'); |
2 | | -var AlignIn = require('../../../utils/align/AlignIn'); |
3 | | -var Zone = require('../../zone/Zone'); |
| 1 | +var CONST = require('../utils/align/const'); |
| 2 | +var AlignIn = require('../utils/align/AlignIn'); |
| 3 | +var Zone = require('../gameobjects/zone/Zone'); |
4 | 4 |
|
5 | 5 | var tempZone = new Zone({}, 0, 0, 1, 1); |
6 | 6 |
|
@@ -53,32 +53,21 @@ var tempZone = new Zone({}, 0, 0, 1, 1); |
53 | 53 | * @param {integer} cellWidth - The width of each grid cell, in pixels. |
54 | 54 | * @param {integer} cellHeight - The height of each grid cell, in pixels. |
55 | 55 | * @param {integer} [position] - The position constant. One of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`. |
56 | | -* @param {integer} [offset=0] - Optional index to start the alignment from. Defaults to zero, the first child in the Group, but can be set to any valid child index value. |
57 | 56 | * @return {boolean} True if the Group children were aligned, otherwise false. |
58 | 57 | */ |
59 | | -var Align = function (width, height, cellWidth, cellHeight, position, offset) |
| 58 | +var GridAlign = function (items, width, height, cellWidth, cellHeight, position) |
60 | 59 | { |
61 | 60 | if (position === undefined) { position = CONST.TOP_LEFT; } |
62 | | - if (offset === undefined) { offset = 0; } |
63 | | - |
64 | | - var children = this.children.entries; |
65 | | - |
66 | | - if (children.length === 0 || offset > children.length || (width === -1 && height === -1)) |
67 | | - { |
68 | | - return false; |
69 | | - } |
70 | 61 |
|
71 | 62 | tempZone.setPosition(0, 0); |
72 | 63 | tempZone.setSize(cellWidth, cellHeight); |
73 | 64 |
|
74 | 65 | var w = (width * cellWidth); |
75 | 66 | var h = (height * cellHeight); |
76 | 67 |
|
77 | | - for (var i = offset; i < children.length; i++) |
| 68 | + for (var i = 0; i < items.length; i++) |
78 | 69 | { |
79 | | - var child = children[i]; |
80 | | - |
81 | | - AlignIn(child, tempZone, position); |
| 70 | + AlignIn(items[i], tempZone, position); |
82 | 71 |
|
83 | 72 | if (width === -1) |
84 | 73 | { |
@@ -114,15 +103,14 @@ var Align = function (width, height, cellWidth, cellHeight, position, offset) |
114 | 103 |
|
115 | 104 | if (tempZone.y === h) |
116 | 105 | { |
117 | | - // We've hit the column limit, so return, even if there are children left |
118 | | - return true; |
| 106 | + // We've hit the column limit, so return, even if there are items left |
| 107 | + break; |
119 | 108 | } |
120 | 109 | } |
121 | 110 | } |
122 | 111 | } |
123 | 112 |
|
124 | | - return true; |
| 113 | + return items; |
125 | 114 | }; |
126 | 115 |
|
127 | | -module.exports = Align; |
128 | | - |
| 116 | +module.exports = GridAlign; |
0 commit comments