mirror of
https://github.com/photonstorm/phaser
synced 2024-11-16 17:58:23 +00:00
Group.addMultiple if given a Group.children array as the first parameter would fail as the original group length was decreased out of line with the children being added. Group.addMultiple now checks if the children argument is a Phaser.Group instance, and if so it uses Group.moveAll instead on it (thanks @AnderbergE #1898)
Group.moveAll allows you to move all of the children of a Group into another Group.
This commit is contained in:
parent
8e92c13412
commit
d3525950a2
3 changed files with 45 additions and 8 deletions
|
@ -331,6 +331,7 @@ Version 2.4 - "Katar" - in dev
|
|||
* All Game Objects have a new boolean property called `pendingDestroy`. If you set this to `true` then the object will automatically destroy itself in the *next* logic update, rather than immediately. This is useful for cases when you wish to destroy an object from within one of its own callbacks, such as with buttons or other input events (thanks @alamboley #1748)
|
||||
* BitmapData.generateTexture will take a snapshot of the BitmapDatas canvas at that moment in time and convert it into an Image, which is then stored in the Phaser image Cache based on the key given. You can then use the new texture for any future sprites or texture based objects.
|
||||
* All Signals now have the ability to carry extra custom arguments with them, which are passed on to the callback you define after any internal arguments. For example a Phaser.Key has an onDown signal. When dispatched onDown sends a reference to the Key as the first and only argument. But you can now set the callback like this: `fireKey.onDown.add(shoot, this, 0, 'lazer', 64)`. So when the onDown signal is dispatched internally the callback (`shoot` in this case) will receive 3 arguments: the Key reference that is raised internally and the string 'lazer' and value 64, which were the custom arguments provided when setting-up the callback.
|
||||
* Group.moveAll allows you to move all of the children of a Group into another Group.
|
||||
|
||||
### Updates
|
||||
|
||||
|
@ -435,6 +436,7 @@ Version 2.4 - "Katar" - in dev
|
|||
* Rope.segments used the wrong vertices property, causing a runtime error.
|
||||
* Debug.ropeSegments didn't take the scale of the Rope object into consideration, causing incorrect debug rendering.
|
||||
* If a Sound was muted, or had its volume changed while it was still decoding (i.e. before it started playback) then the mute and/or volume were ignored and the sound would play anyway (thanks @brianbunch #1872)
|
||||
* Group.addMultiple if given a Group.children array as the first parameter would fail as the original group length was decreased out of line with the children being added. Group.addMultiple now checks if the children argument is a Phaser.Group instance, and if so it uses Group.moveAll instead on it (thanks @AnderbergE #1898)
|
||||
|
||||
### Deprecated
|
||||
|
||||
|
|
|
@ -362,20 +362,25 @@ Phaser.Group.prototype.removeFromHash = function (child) {
|
|||
};
|
||||
|
||||
/**
|
||||
* Adds an array of existing display objects to this group.
|
||||
* Adds an array of existing Display Objects to this Group.
|
||||
*
|
||||
* The children are automatically added to the top of the group, so render on-top of everything else within the group.
|
||||
* The Display Objects are automatically added to the top of this Group, and will render on-top of everything already in this Group.
|
||||
*
|
||||
* TODO: Add ability to pass the children as parameters rather than having to be an array.
|
||||
* As well as an array you can also pass another Group as the first argument. In this case all of the children from that
|
||||
* Group will be removed from it and added into this Group.
|
||||
*
|
||||
* @method Phaser.Group#addMultiple
|
||||
* @param {DisplayObject[]} children - An array of display objects to add as children.
|
||||
* @param {DisplayObject[]|Phaser.Group} children - An array of display objects or a Phaser.Group. If a Group is given then *all* children will be moved from it.
|
||||
* @param {boolean} [silent=false] - If true the children will not dispatch the `onAddedToGroup` event.
|
||||
* @return {DisplayObject[]} The array of children that were added to the group.
|
||||
* @return {DisplayObject[]|Phaser.Group} The array of children or Group of children that were added to this Group.
|
||||
*/
|
||||
Phaser.Group.prototype.addMultiple = function (children, silent) {
|
||||
|
||||
if (Array.isArray(children))
|
||||
if (children instanceof Phaser.Group)
|
||||
{
|
||||
children.moveAll(this, silent);
|
||||
}
|
||||
else if (Array.isArray(children))
|
||||
{
|
||||
for (var i = 0; i < children.length; i++)
|
||||
{
|
||||
|
@ -504,7 +509,7 @@ Phaser.Group.prototype.create = function (x, y, key, frame, exists) {
|
|||
* Useful if you need to quickly generate a pool of identical sprites, such as bullets.
|
||||
*
|
||||
* By default the sprites will be set to not exist and will be positioned at 0, 0 (relative to the group.x/y).
|
||||
* Use {@link #classType} to change the type of object creaded.
|
||||
* Use {@link #classType} to change the type of object created.
|
||||
*
|
||||
* @method Phaser.Group#createMultiple
|
||||
* @param {integer} quantity - The number of Sprites to create.
|
||||
|
@ -524,7 +529,7 @@ Phaser.Group.prototype.createMultiple = function (quantity, key, frame, exists)
|
|||
};
|
||||
|
||||
/**
|
||||
* Internal method that re-applies all of the childrens Z values.
|
||||
* Internal method that re-applies all of the children's Z values.
|
||||
*
|
||||
* This must be called whenever children ordering is altered so that their `z` indices are correctly updated.
|
||||
*
|
||||
|
@ -1929,6 +1934,35 @@ Phaser.Group.prototype.remove = function (child, destroy, silent) {
|
|||
|
||||
};
|
||||
|
||||
/**
|
||||
* Moves all children from this Group to the Group given.
|
||||
*
|
||||
* @method Phaser.Group#moveAll
|
||||
* @param {Phaser.Group} group - The new Group to which the children will be moved to.
|
||||
* @param {boolean} [silent=false] - If true the children will not dispatch the `onAddedToGroup` event for the new Group.
|
||||
* @return {Phaser.Group} The Group to which all the children were moved.
|
||||
*/
|
||||
Phaser.Group.prototype.moveAll = function (group, silent) {
|
||||
|
||||
if (typeof silent === 'undefined') { silent = false; }
|
||||
|
||||
if (this.children.length > 0 && group instanceof Phaser.Group)
|
||||
{
|
||||
do
|
||||
{
|
||||
group.add(this.children[0], silent);
|
||||
}
|
||||
while (this.children.length > 0);
|
||||
|
||||
this.hash = [];
|
||||
|
||||
this.cursor = null;
|
||||
}
|
||||
|
||||
return group;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes all children from this group, but does not remove the group from its parent.
|
||||
*
|
||||
|
|
1
typescript/phaser.d.ts
vendored
1
typescript/phaser.d.ts
vendored
|
@ -1543,6 +1543,7 @@ declare module Phaser {
|
|||
getTop(): any;
|
||||
hasProperty(child: any, key: string[]): boolean;
|
||||
iterate(key: string, value: any, returnType: number, callback?: Function, callbackContext?: any, ...args: any[]): any;
|
||||
moveAll(group: Phaser.Group, silent?: boolean): Phaser.Group;
|
||||
moveDown(child: any): any;
|
||||
moveUp(child: any): any;
|
||||
multiplyAll(property: string, amount: number, checkAlive: boolean, checkVisible: boolean): void;
|
||||
|
|
Loading…
Reference in a new issue