Group.align updates.

This commit is contained in:
Richard Davey 2016-07-20 12:29:30 +01:00
parent 0e24b1b946
commit 60b8d78ab8
3 changed files with 20 additions and 15 deletions

View file

@ -321,7 +321,8 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
* The InputHandler.flagged property has been removed. It was never used internally, or exposed via the API, so was just overhead.
* The src/system folder has been removed and all files relocated to the src/utils folder. This doesn't change anything from an API point of view, but did change the grunt build scripts slightly.
* BitmapData.shadow and BitmapData.text now both `return this` keeping them in-line with the docs (thanks @greeny #2634)
* Group.align has had its argument orders swapped, so that it's now `(columns, rows, ...)` instead of `(rows, columns, ...)` (thanks @deargle #2643)
* Group.align has had its arguments changed so that it's now `(width, height, ...)` instead of `(rows, columns, ...)` (thanks @deargle #2643)
* Group.align now returns `true` if the Group was aligned, or `false` if not.
### Bug Fixes

View file

@ -685,7 +685,7 @@ Phaser.Group.prototype.updateZ = function () {
* the `alignTo` method in order to be positioned by this call. All default Phaser Game Objects have
* this.
*
* The grid dimensions are determined by the first four arguments. The `rows` and `columns` arguments
* The grid dimensions are determined by the first four arguments. The `width` and `height` arguments
* relate to the width and height of the grid respectively.
*
* For example if the Group had 100 children in it:
@ -699,13 +699,13 @@ Phaser.Group.prototype.updateZ = function () {
*
* This will align the children into a grid of 25x4, again using 32 pixels per grid cell.
*
* You can choose to set _either_ the `rows` or `columns` value to -1. Doing so tells the method
* You can choose to set _either_ the `width` or `height` value to -1. Doing so tells the method
* to keep on aligning children until there are no children left. For example if this Group had
* 48 children in it, the following:
*
* `Group.align(-1, 8, 32, 32)`
*
* ... will align the children so that there are 8 rows vertically (the second argument),
* ... will align the children so that there are 8 children vertically (the second argument),
* and each row will contain 6 sprites, except the last one, which will contain 5 (totaling 48)
*
* You can also do:
@ -723,26 +723,27 @@ Phaser.Group.prototype.updateZ = function () {
* The final argument; `offset` lets you start the alignment from a specific child index.
*
* @method Phaser.Group#align
* @param {integer} columns - The number of columns, or width, of the grid. Set to -1 for a dynamic width.
* @param {integer} rows - The number of rows, or height, of the grid. Set to -1 for a dynamic height.
* @param {integer} width - The width of the grid in items (not pixels). Set to -1 for a dynamic width. If -1 then you must set an explicit height value.
* @param {integer} height - The height of the grid in items (not pixels). Set to -1 for a dynamic height. If -1 then you must set an explicit width value.
* @param {integer} cellWidth - The width of each grid cell, in pixels.
* @param {integer} cellHeight - The height of each grid cell, in pixels.
* @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`.
* @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.
* @return {boolean} True if the Group children were aligned, otherwise false.
*/
Phaser.Group.prototype.align = function (columns, rows, cellWidth, cellHeight, position, offset) {
Phaser.Group.prototype.align = function (width, height, cellWidth, cellHeight, position, offset) {
if (position === undefined) { position = Phaser.TOP_LEFT; }
if (offset === undefined) { offset = 0; }
if (this.children.length === 0 || offset > this.children.length || (columns === -1 && rows === -1))
if (this.children.length === 0 || offset > this.children.length || (width === -1 && height === -1))
{
return;
return false;
}
var r = new Phaser.Rectangle(0, 0, cellWidth, cellHeight);
var w = (columns * cellWidth);
var h = (rows * cellHeight);
var w = (width * cellWidth);
var h = (height * cellHeight);
for (var i = offset; i < this.children.length; i++)
{
@ -757,7 +758,7 @@ Phaser.Group.prototype.align = function (columns, rows, cellWidth, cellHeight, p
continue;
}
if (columns === -1)
if (width === -1)
{
// We keep laying them out horizontally until we've done them all
r.y += cellHeight;
@ -768,7 +769,7 @@ Phaser.Group.prototype.align = function (columns, rows, cellWidth, cellHeight, p
r.y = 0;
}
}
else if (rows === -1)
else if (height === -1)
{
// We keep laying them out vertically until we've done them all
r.x += cellWidth;
@ -792,12 +793,14 @@ Phaser.Group.prototype.align = function (columns, rows, cellWidth, cellHeight, p
if (r.y === h)
{
// We've hit the column limit, so return, even if there are children left
return;
return true;
}
}
}
}
return true;
};
/**

View file

@ -1719,6 +1719,7 @@ declare module Phaser {
static RETURN_CHILD: number;
static RETURN_NONE: number;
static RETURN_TOTAL: number;
static RETURN_ALL: number;
static SORT_ASCENDING: number;
static SORT_DESCENDING: number;
@ -1767,7 +1768,7 @@ declare module Phaser {
addAt(child: any, index: number, silent?: boolean): any;
addMultiple(children: any[], silent?: boolean): any[];
addToHash(child: PIXI.DisplayObject): boolean;
align(rows: number, columns: number, cellWidth: number, cellHeight: number, position?: number, offset?: number): void;
align(width: number, height: number, cellWidth: number, cellHeight: number, position?: number, offset?: number): boolean;
alignIn(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): Phaser.Group;
alignTo(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): Phaser.Group;
bringToTop(child: any): any;