mirror of
https://github.com/photonstorm/phaser
synced 2024-11-30 08:31:01 +00:00
GridAlign now takes a config object, and works with optional x/y settings too.
This commit is contained in:
parent
2cfa57e35c
commit
7f72c7b8ca
3 changed files with 30 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
|||
var CONST = require('../utils/align/const');
|
||||
var AlignIn = require('../utils/align/AlignIn');
|
||||
var Zone = require('../gameobjects/zone/Zone');
|
||||
var GetObjectValue = require('../utils/object/GetObjectValue');
|
||||
|
||||
var tempZone = new Zone({}, 0, 0, 1, 1);
|
||||
|
||||
|
@ -55,13 +56,21 @@ var tempZone = new Zone({}, 0, 0, 1, 1);
|
|||
* @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`.
|
||||
* @return {boolean} True if the Group children were aligned, otherwise false.
|
||||
*/
|
||||
var GridAlign = function (items, width, height, cellWidth, cellHeight, position)
|
||||
var GridAlign = function (items, options)
|
||||
{
|
||||
if (position === undefined) { position = CONST.TOP_LEFT; }
|
||||
var width = GetObjectValue(options, 'width', -1);
|
||||
var height = GetObjectValue(options, 'height', -1);
|
||||
var cellWidth = GetObjectValue(options, 'cellWidth', 1);
|
||||
var cellHeight = GetObjectValue(options, 'cellHeight', cellWidth);
|
||||
var position = GetObjectValue(options, 'position', CONST.TOP_LEFT);
|
||||
var x = GetObjectValue(options, 'x', 0);
|
||||
var y = GetObjectValue(options, 'y', 0);
|
||||
|
||||
tempZone.setPosition(0, 0);
|
||||
tempZone.setPosition(x, y);
|
||||
tempZone.setSize(cellWidth, cellHeight);
|
||||
|
||||
var cx = 0;
|
||||
var cy = 0;
|
||||
var w = (width * cellWidth);
|
||||
var h = (height * cellHeight);
|
||||
|
||||
|
@ -72,36 +81,43 @@ var GridAlign = function (items, width, height, cellWidth, cellHeight, position)
|
|||
if (width === -1)
|
||||
{
|
||||
// We keep laying them out horizontally until we've done them all
|
||||
cy += cellHeight;
|
||||
tempZone.y += cellHeight;
|
||||
|
||||
if (tempZone.y === h)
|
||||
if (cy === h)
|
||||
{
|
||||
cy = 0;
|
||||
tempZone.x += cellWidth;
|
||||
tempZone.y = 0;
|
||||
tempZone.y = y;
|
||||
}
|
||||
}
|
||||
else if (height === -1)
|
||||
{
|
||||
// We keep laying them out vertically until we've done them all
|
||||
cx += cellWidth;
|
||||
tempZone.x += cellWidth;
|
||||
|
||||
if (tempZone.x === w)
|
||||
if (cx === w)
|
||||
{
|
||||
tempZone.x = 0;
|
||||
cx = 0;
|
||||
tempZone.x = x;
|
||||
tempZone.y += cellHeight;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// We keep laying them out until we hit the column limit
|
||||
cx += cellWidth;
|
||||
tempZone.x += cellWidth;
|
||||
|
||||
if (tempZone.x === w)
|
||||
if (cx === w)
|
||||
{
|
||||
tempZone.x = 0;
|
||||
cx = 0;
|
||||
cy += cellHeight;
|
||||
tempZone.x = x;
|
||||
tempZone.y += cellHeight;
|
||||
|
||||
if (tempZone.y === h)
|
||||
if (cy === h)
|
||||
{
|
||||
// We've hit the column limit, so return, even if there are items left
|
||||
break;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: '448d6cb0-1414-11e7-9400-83d0899b34cd'
|
||||
build: '5d589820-1417-11e7-a4fb-712e101ac5d8'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
|
@ -86,7 +86,7 @@ var Layer = new Class({
|
|||
var randomKey = GetObjectValue(options, 'randomKey', false);
|
||||
var randomFrame = GetObjectValue(options, 'randomFrame', false);
|
||||
var yoyo = GetObjectValue(options, 'yoyo', false);
|
||||
var quantity = GetObjectValue(options, 'quantity', 1);
|
||||
var quantity = GetObjectValue(options, 'frameQuantity', 1);
|
||||
var max = GetObjectValue(options, 'max', 0);
|
||||
|
||||
var range = Range(key, frame, {
|
||||
|
@ -182,9 +182,9 @@ var Layer = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
gridAlign: function (width, height, cellWidth, cellHeight, position)
|
||||
gridAlign: function (options)
|
||||
{
|
||||
Actions.GridAlign(this.children.entries, width, height, cellWidth, cellHeight, position);
|
||||
Actions.GridAlign(this.children.entries, options);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue