mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 05:33:35 +00:00
Added Group.GetLast
This commit is contained in:
parent
6772a548dc
commit
5b4feedcaf
1 changed files with 84 additions and 12 deletions
|
@ -706,6 +706,58 @@ var Group = new Class({
|
|||
* @return {?Phaser.GameObjects.GameObject} The first matching group member, or a newly created member, or null.
|
||||
*/
|
||||
getFirst: function (state, createIfNull, x, y, key, frame, visible)
|
||||
{
|
||||
return this.getHandler(true, state, createIfNull, x, y, key, frame, visible);
|
||||
},
|
||||
|
||||
/**
|
||||
* Scans the group for the last member that has an {@link Phaser.GameObjects.GameObject#active} state matching the argument,
|
||||
* assigns `x` and `y`, and returns the member.
|
||||
*
|
||||
* If no matching member is found and `createIfNull` is true and the group isn't full then it will create a new Game Object using `x`, `y`, `key`, `frame`, and `visible`.
|
||||
* Unless a new member is created, `key`, `frame`, and `visible` are ignored.
|
||||
*
|
||||
* @method Phaser.GameObjects.Group#getLast
|
||||
* @since 3.6.0
|
||||
*
|
||||
* @param {boolean} [state=false] - The {@link Phaser.GameObjects.GameObject#active} value to match.
|
||||
* @param {boolean} [createIfNull=false] - Create a new Game Object if no matching members are found, using the following arguments.
|
||||
* @param {number} [x] - The horizontal position of the Game Object in the world.
|
||||
* @param {number} [y] - The vertical position of the Game Object in the world.
|
||||
* @param {string} [key=defaultKey] - The texture key assigned to a new Game Object (if one is created).
|
||||
* @param {(string|integer)} [frame=defaultFrame] - A texture frame assigned to a new Game Object (if one is created).
|
||||
* @param {boolean} [visible=true] - The {@link Phaser.GameObjects.Components.Visible#visible} state of a new Game Object (if one is created).
|
||||
*
|
||||
* @return {?Phaser.GameObjects.GameObject} The first matching group member, or a newly created member, or null.
|
||||
*/
|
||||
getLast: function (state, createIfNull, x, y, key, frame, visible)
|
||||
{
|
||||
return this.getHandler(false, state, createIfNull, x, y, key, frame, visible);
|
||||
},
|
||||
|
||||
/**
|
||||
* Scans the group for the last member that has an {@link Phaser.GameObjects.GameObject#active} state matching the argument,
|
||||
* assigns `x` and `y`, and returns the member.
|
||||
*
|
||||
* If no matching member is found and `createIfNull` is true and the group isn't full then it will create a new Game Object using `x`, `y`, `key`, `frame`, and `visible`.
|
||||
* Unless a new member is created, `key`, `frame`, and `visible` are ignored.
|
||||
*
|
||||
* @method Phaser.GameObjects.Group#getHandler
|
||||
* @private
|
||||
* @since 3.6.0
|
||||
*
|
||||
* @param {boolean} forwards - Search front to back or back to front?
|
||||
* @param {boolean} [state=false] - The {@link Phaser.GameObjects.GameObject#active} value to match.
|
||||
* @param {boolean} [createIfNull=false] - Create a new Game Object if no matching members are found, using the following arguments.
|
||||
* @param {number} [x] - The horizontal position of the Game Object in the world.
|
||||
* @param {number} [y] - The vertical position of the Game Object in the world.
|
||||
* @param {string} [key=defaultKey] - The texture key assigned to a new Game Object (if one is created).
|
||||
* @param {(string|integer)} [frame=defaultFrame] - A texture frame assigned to a new Game Object (if one is created).
|
||||
* @param {boolean} [visible=true] - The {@link Phaser.GameObjects.Components.Visible#visible} state of a new Game Object (if one is created).
|
||||
*
|
||||
* @return {?Phaser.GameObjects.GameObject} The first matching group member, or a newly created member, or null.
|
||||
*/
|
||||
getHandler: function (forwards, state, createIfNull, x, y, key, frame, visible)
|
||||
{
|
||||
if (state === undefined) { state = false; }
|
||||
if (createIfNull === undefined) { createIfNull = false; }
|
||||
|
@ -714,25 +766,45 @@ var Group = new Class({
|
|||
|
||||
var children = this.children.entries;
|
||||
|
||||
for (var i = 0; i < children.length; i++)
|
||||
if (forwards)
|
||||
{
|
||||
gameObject = children[i];
|
||||
|
||||
if (gameObject.active === state)
|
||||
for (var i = 0; i < children.length; i++)
|
||||
{
|
||||
if (typeof(x) === 'number')
|
||||
{
|
||||
gameObject.x = x;
|
||||
}
|
||||
gameObject = children[i];
|
||||
|
||||
if (typeof(y) === 'number')
|
||||
if (gameObject.active === state)
|
||||
{
|
||||
gameObject.y = y;
|
||||
break;
|
||||
}
|
||||
|
||||
return gameObject;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (var i = children.length - 1; i >= 0; i--)
|
||||
{
|
||||
gameObject = children[i];
|
||||
|
||||
if (gameObject.active === state)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gameObject)
|
||||
{
|
||||
if (typeof(x) === 'number')
|
||||
{
|
||||
gameObject.x = x;
|
||||
}
|
||||
|
||||
if (typeof(y) === 'number')
|
||||
{
|
||||
gameObject.y = y;
|
||||
}
|
||||
|
||||
return gameObject;
|
||||
}
|
||||
|
||||
// Got this far? We need to create or bail
|
||||
if (createIfNull)
|
||||
|
|
Loading…
Reference in a new issue