2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2013 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
* @module Phaser.Group
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Phaser Group constructor.
|
|
|
|
* @class Phaser.Group
|
|
|
|
* @classdesc An Animation instance contains a single animation and the controls to play it.
|
|
|
|
* It is created by the AnimationManager, consists of Animation.Frame objects and belongs to a single Game Object such as a Sprite.
|
|
|
|
* @constructor
|
|
|
|
* @param {Phaser.Game} game - A reference to the currently running game.
|
|
|
|
* @param {Description} parent - Description.
|
|
|
|
* @param {string} name - The unique name for this animation, used in playback commands.
|
|
|
|
* @param {bool} useStage - Description.
|
|
|
|
*/
|
2013-09-11 12:21:07 +00:00
|
|
|
Phaser.Group = function (game, parent, name, useStage) {
|
2013-09-06 19:20:58 +00:00
|
|
|
|
|
|
|
parent = parent || null;
|
2013-09-05 20:07:44 +00:00
|
|
|
|
2013-09-11 12:21:07 +00:00
|
|
|
if (typeof useStage == 'undefined')
|
|
|
|
{
|
|
|
|
useStage = false;
|
|
|
|
}
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Game} game - A reference to the currently running Game.
|
|
|
|
*/
|
2013-09-05 20:07:44 +00:00
|
|
|
this.game = game;
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Game} name - Description.
|
|
|
|
*/
|
2013-09-06 19:20:58 +00:00
|
|
|
this.name = name || 'group';
|
2013-09-05 20:07:44 +00:00
|
|
|
|
2013-09-11 12:21:07 +00:00
|
|
|
if (useStage)
|
|
|
|
{
|
|
|
|
this._container = this.game.stage._stage;
|
|
|
|
}
|
|
|
|
else
|
2013-09-06 19:20:58 +00:00
|
|
|
{
|
2013-09-11 12:21:07 +00:00
|
|
|
this._container = new PIXI.DisplayObjectContainer();
|
|
|
|
this._container.name = this.name;
|
|
|
|
|
|
|
|
if (parent)
|
2013-09-10 11:46:14 +00:00
|
|
|
{
|
2013-09-11 12:21:07 +00:00
|
|
|
if (parent instanceof Phaser.Group)
|
|
|
|
{
|
|
|
|
parent._container.addChild(this._container);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parent.addChild(this._container);
|
|
|
|
}
|
2013-09-10 11:46:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-11 12:21:07 +00:00
|
|
|
this.game.stage._stage.addChild(this._container);
|
2013-09-10 11:46:14 +00:00
|
|
|
}
|
2013-09-06 19:20:58 +00:00
|
|
|
}
|
2013-09-05 20:07:44 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {Description} type - Description.
|
|
|
|
*/
|
2013-09-12 20:54:41 +00:00
|
|
|
this.type = Phaser.GROUP;
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {bool} exists - Description.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-05 20:07:44 +00:00
|
|
|
this.exists = true;
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {string} _sortIndex - Helper for sort.
|
|
|
|
* @private
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-05 20:07:44 +00:00
|
|
|
this._sortIndex = 'y';
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.Group.prototype = {
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method add
|
|
|
|
* @param {Description} child - Description.
|
|
|
|
* @return {Description} Description.
|
|
|
|
*/
|
2013-09-05 20:07:44 +00:00
|
|
|
add: function (child) {
|
|
|
|
|
|
|
|
if (child.group !== this)
|
|
|
|
{
|
|
|
|
child.group = this;
|
2013-09-12 03:24:01 +00:00
|
|
|
|
|
|
|
if (child.events)
|
|
|
|
{
|
|
|
|
child.events.onAddedToGroup.dispatch(child, this);
|
|
|
|
}
|
|
|
|
|
2013-09-05 20:07:44 +00:00
|
|
|
this._container.addChild(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
return child;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method addAt
|
|
|
|
* @param {Description} child - Description.
|
|
|
|
* @param {Description} index - Description.
|
|
|
|
* @return {Description} Description.
|
|
|
|
*/
|
2013-09-05 20:07:44 +00:00
|
|
|
addAt: function (child, index) {
|
|
|
|
|
|
|
|
if (child.group !== this)
|
|
|
|
{
|
|
|
|
child.group = this;
|
2013-09-12 03:24:01 +00:00
|
|
|
|
|
|
|
if (child.events)
|
|
|
|
{
|
|
|
|
child.events.onAddedToGroup.dispatch(child, this);
|
|
|
|
}
|
|
|
|
|
2013-09-05 20:07:44 +00:00
|
|
|
this._container.addChildAt(child, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
return child;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method getAt
|
|
|
|
* @param {Description} index - Description.
|
|
|
|
* @return {Description} Description.
|
|
|
|
*/
|
2013-09-06 19:20:58 +00:00
|
|
|
getAt: function (index) {
|
2013-09-05 20:07:44 +00:00
|
|
|
|
|
|
|
return this._container.getChildAt(index);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method create
|
|
|
|
* @param {number} x - Description.
|
|
|
|
* @param {number} y - Description.
|
|
|
|
* @param {string} key - Description.
|
|
|
|
* @param {string} [frame] - Description.
|
|
|
|
* @param {boolean} [exists] - Description.
|
|
|
|
* @return {Description} Description.
|
|
|
|
*/
|
2013-09-14 23:14:45 +00:00
|
|
|
create: function (x, y, key, frame, exists) {
|
|
|
|
|
|
|
|
if (typeof exists == 'undefined') { exists = true; }
|
2013-09-05 20:07:44 +00:00
|
|
|
|
|
|
|
var child = new Phaser.Sprite(this.game, x, y, key, frame);
|
2013-09-12 03:24:01 +00:00
|
|
|
|
2013-09-06 14:00:05 +00:00
|
|
|
child.group = this;
|
2013-09-14 23:14:45 +00:00
|
|
|
child.exists = exists;
|
2013-09-12 03:24:01 +00:00
|
|
|
|
|
|
|
if (child.events)
|
|
|
|
{
|
|
|
|
child.events.onAddedToGroup.dispatch(child, this);
|
|
|
|
}
|
|
|
|
|
2013-09-05 20:07:44 +00:00
|
|
|
this._container.addChild(child);
|
2013-09-12 03:24:01 +00:00
|
|
|
|
2013-09-05 20:07:44 +00:00
|
|
|
return child;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method swap
|
|
|
|
* @param {Description} child1 - Description.
|
|
|
|
* @param {Description} child2 - Description.
|
|
|
|
* @return {bool} Description.
|
|
|
|
*/
|
2013-09-05 20:07:44 +00:00
|
|
|
swap: function (child1, child2) {
|
|
|
|
|
2013-09-06 14:00:05 +00:00
|
|
|
if (child1 === child2 || !child1.parent || !child2.parent)
|
|
|
|
{
|
|
|
|
console.warn('You cannot swap a child with itself or swap un-parented children');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cache the values
|
|
|
|
var child1Prev = child1._iPrev;
|
|
|
|
var child1Next = child1._iNext;
|
|
|
|
var child2Prev = child2._iPrev;
|
|
|
|
var child2Next = child2._iNext;
|
|
|
|
|
|
|
|
var endNode = this._container.last._iNext;
|
2013-09-10 11:46:14 +00:00
|
|
|
var currentNode = this.game.stage._stage;
|
2013-09-06 14:00:05 +00:00
|
|
|
|
2013-09-10 11:46:14 +00:00
|
|
|
do
|
2013-09-06 14:00:05 +00:00
|
|
|
{
|
|
|
|
if (currentNode !== child1 && currentNode !== child2)
|
|
|
|
{
|
|
|
|
if (currentNode.first === child1)
|
|
|
|
{
|
|
|
|
currentNode.first = child2;
|
|
|
|
}
|
|
|
|
else if (currentNode.first === child2)
|
|
|
|
{
|
|
|
|
currentNode.first = child1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentNode.last === child1)
|
|
|
|
{
|
|
|
|
currentNode.last = child2;
|
|
|
|
}
|
|
|
|
else if (currentNode.last === child2)
|
|
|
|
{
|
|
|
|
currentNode.last = child1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
currentNode = currentNode._iNext;
|
|
|
|
}
|
|
|
|
while (currentNode != endNode)
|
|
|
|
|
|
|
|
if (child1._iNext == child2)
|
|
|
|
{
|
|
|
|
// This is a downward (A to B) neighbour swap
|
|
|
|
child1._iNext = child2Next;
|
|
|
|
child1._iPrev = child2;
|
|
|
|
child2._iNext = child1;
|
|
|
|
child2._iPrev = child1Prev;
|
|
|
|
|
|
|
|
if (child1Prev) { child1Prev._iNext = child2; }
|
|
|
|
if (child2Next) { child2Next._iPrev = child1; }
|
|
|
|
|
2013-09-10 15:46:39 +00:00
|
|
|
if (child1.__renderGroup)
|
|
|
|
{
|
|
|
|
child1.__renderGroup.updateTexture(child1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child2.__renderGroup)
|
|
|
|
{
|
|
|
|
child2.__renderGroup.updateTexture(child2);
|
|
|
|
}
|
|
|
|
|
2013-09-06 14:00:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (child2._iNext == child1)
|
|
|
|
{
|
|
|
|
// This is an upward (B to A) neighbour swap
|
|
|
|
child1._iNext = child2;
|
|
|
|
child1._iPrev = child2Prev;
|
|
|
|
child2._iNext = child1Next;
|
|
|
|
child2._iPrev = child1;
|
|
|
|
|
|
|
|
if (child2Prev) { child2Prev._iNext = child1; }
|
|
|
|
if (child1Next) { child2Next._iPrev = child2; }
|
|
|
|
|
2013-09-10 15:46:39 +00:00
|
|
|
if (child1.__renderGroup)
|
|
|
|
{
|
|
|
|
child1.__renderGroup.updateTexture(child1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child2.__renderGroup)
|
|
|
|
{
|
|
|
|
child2.__renderGroup.updateTexture(child2);
|
|
|
|
}
|
|
|
|
|
2013-09-06 14:00:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Children are far apart
|
|
|
|
child1._iNext = child2Next;
|
|
|
|
child1._iPrev = child2Prev;
|
|
|
|
child2._iNext = child1Next;
|
|
|
|
child2._iPrev = child1Prev;
|
|
|
|
|
|
|
|
if (child1Prev) { child1Prev._iNext = child2; }
|
|
|
|
if (child1Next) { child1Next._iPrev = child2; }
|
|
|
|
if (child2Prev) { child2Prev._iNext = child1; }
|
|
|
|
if (child2Next) { child2Next._iPrev = child1; }
|
|
|
|
|
2013-09-10 15:46:39 +00:00
|
|
|
if (child1.__renderGroup)
|
|
|
|
{
|
|
|
|
child1.__renderGroup.updateTexture(child1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child2.__renderGroup)
|
|
|
|
{
|
|
|
|
child2.__renderGroup.updateTexture(child2);
|
|
|
|
}
|
|
|
|
|
2013-09-06 14:00:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-09-05 20:07:44 +00:00
|
|
|
|
2013-09-06 14:00:05 +00:00
|
|
|
return false;
|
|
|
|
|
2013-09-05 20:07:44 +00:00
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method bringToTop
|
|
|
|
* @param {Description} child - Description.
|
|
|
|
* @return {Description} Description.
|
|
|
|
*/
|
2013-09-05 20:07:44 +00:00
|
|
|
bringToTop: function (child) {
|
|
|
|
|
2013-09-10 11:46:14 +00:00
|
|
|
if (child.group === this)
|
2013-09-06 14:00:05 +00:00
|
|
|
{
|
2013-09-10 11:46:14 +00:00
|
|
|
this.remove(child);
|
|
|
|
this.add(child);
|
2013-09-06 14:00:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return child;
|
2013-09-05 20:07:44 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method getIndex
|
|
|
|
* @param {Description} child - Description.
|
|
|
|
* @return {Description} Description.
|
|
|
|
*/
|
2013-09-06 19:20:58 +00:00
|
|
|
getIndex: function (child) {
|
|
|
|
|
|
|
|
return this._container.children.indexOf(child);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method replace
|
|
|
|
* @param {Description} oldChild - Description.
|
|
|
|
* @param {Description} newChild - Description.
|
|
|
|
*/
|
2013-09-06 19:20:58 +00:00
|
|
|
replace: function (oldChild, newChild) {
|
|
|
|
|
|
|
|
if (!this._container.first._iNext)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var index = this.getIndex(oldChild);
|
|
|
|
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
if (newChild.parent != undefined)
|
|
|
|
{
|
2013-09-09 12:29:33 +00:00
|
|
|
newChild.events.onRemovedFromGroup.dispatch(newChild, this);
|
2013-09-06 19:20:58 +00:00
|
|
|
newChild.parent.removeChild(newChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._container.removeChild(oldChild);
|
|
|
|
this._container.addChildAt(newChild, index);
|
2013-09-09 12:29:33 +00:00
|
|
|
newChild.events.onAddedToGroup.dispatch(newChild, this);
|
2013-09-06 19:20:58 +00:00
|
|
|
}
|
|
|
|
|
2013-09-05 20:07:44 +00:00
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method setProperty
|
|
|
|
* @param {Description} child - Description.
|
|
|
|
* @param {array} key - An array of values that will be set.
|
|
|
|
* @param {Description} value - Description.
|
|
|
|
* @param {Description} operation - Description.
|
|
|
|
* @return {number} An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2). (TODO)
|
|
|
|
*/
|
2013-09-06 14:00:05 +00:00
|
|
|
setProperty: function (child, key, value, operation) {
|
|
|
|
|
|
|
|
operation = operation || 0;
|
|
|
|
|
|
|
|
// As ugly as this approach looks, and although it's limited to a depth of only 4, it's extremely fast.
|
|
|
|
// Much faster than a for loop or object iteration. There are no checks, so if the key isn't valid then it'll fail
|
|
|
|
// but as you are likely to call this from inner loops that have to perform well, I'll take that trade off.
|
|
|
|
|
|
|
|
// 0 = Equals
|
|
|
|
// 1 = Add
|
|
|
|
// 2 = Subtract
|
|
|
|
// 3 = Multiply
|
|
|
|
// 4 = Divide
|
|
|
|
|
|
|
|
if (key.length == 1)
|
|
|
|
{
|
|
|
|
if (operation == 0) { child[key[0]] = value; }
|
|
|
|
else if (operation == 1) { child[key[0]] += value; }
|
|
|
|
else if (operation == 2) { child[key[0]] -= value; }
|
|
|
|
else if (operation == 3) { child[key[0]] *= value; }
|
|
|
|
else if (operation == 4) { child[key[0]] /= value; }
|
|
|
|
}
|
|
|
|
else if (key.length == 2)
|
|
|
|
{
|
|
|
|
if (operation == 0) { child[key[0]][key[1]] = value; }
|
|
|
|
else if (operation == 1) { child[key[0]][key[1]] += value; }
|
|
|
|
else if (operation == 2) { child[key[0]][key[1]] -= value; }
|
|
|
|
else if (operation == 3) { child[key[0]][key[1]] *= value; }
|
|
|
|
else if (operation == 4) { child[key[0]][key[1]] /= value; }
|
|
|
|
}
|
|
|
|
else if (key.length == 3)
|
|
|
|
{
|
|
|
|
if (operation == 0) { child[key[0]][key[1]][key[2]] = value; }
|
|
|
|
else if (operation == 1) { child[key[0]][key[1]][key[2]] += value; }
|
|
|
|
else if (operation == 2) { child[key[0]][key[1]][key[2]] -= value; }
|
|
|
|
else if (operation == 3) { child[key[0]][key[1]][key[2]] *= value; }
|
|
|
|
else if (operation == 4) { child[key[0]][key[1]][key[2]] /= value; }
|
|
|
|
}
|
|
|
|
else if (key.length == 4)
|
|
|
|
{
|
|
|
|
if (operation == 0) { child[key[0]][key[1]][key[2]][key[3]] = value; }
|
|
|
|
else if (operation == 1) { child[key[0]][key[1]][key[2]][key[3]] += value; }
|
|
|
|
else if (operation == 2) { child[key[0]][key[1]][key[2]][key[3]] -= value; }
|
|
|
|
else if (operation == 3) { child[key[0]][key[1]][key[2]][key[3]] *= value; }
|
|
|
|
else if (operation == 4) { child[key[0]][key[1]][key[2]][key[3]] /= value; }
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// TODO - Deep property scane
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method setAll
|
|
|
|
* @param {Description} key - Description.
|
|
|
|
* @param {Description} value - Description.
|
|
|
|
* @param {Description} checkAlive - Description.
|
|
|
|
* @param {Description} checkVisible - Description.
|
|
|
|
* @param {Description} operation - Description.
|
|
|
|
*/
|
2013-09-06 14:00:05 +00:00
|
|
|
setAll: function (key, value, checkAlive, checkVisible, operation) {
|
|
|
|
|
|
|
|
key = key.split('.');
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
if (typeof checkAlive === 'undefined') { checkAlive = false; }
|
|
|
|
if (typeof checkVisible === 'undefined') { checkVisible = false; }
|
|
|
|
|
2013-09-06 14:00:05 +00:00
|
|
|
operation = operation || 0;
|
|
|
|
|
2013-09-14 23:14:45 +00:00
|
|
|
if (this._container.children.length > 0 && this._container.first._iNext)
|
2013-09-06 14:00:05 +00:00
|
|
|
{
|
2013-09-06 19:20:58 +00:00
|
|
|
var currentNode = this._container.first._iNext;
|
|
|
|
|
|
|
|
do
|
2013-09-06 14:00:05 +00:00
|
|
|
{
|
2013-09-06 19:20:58 +00:00
|
|
|
if ((checkAlive == false || (checkAlive && currentNode.alive)) && (checkVisible == false || (checkVisible && currentNode.visible)))
|
|
|
|
{
|
|
|
|
this.setProperty(currentNode, key, value, operation);
|
|
|
|
}
|
2013-09-06 14:00:05 +00:00
|
|
|
|
2013-09-06 19:20:58 +00:00
|
|
|
currentNode = currentNode._iNext;
|
|
|
|
}
|
|
|
|
while (currentNode != this._container.last._iNext)
|
2013-09-06 14:00:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Adds the amount to the given property on all children in this Group.
|
|
|
|
* Group.addAll('x', 10) will add 10 to the child.x value.
|
|
|
|
*
|
|
|
|
* @method addAll
|
|
|
|
* @param {string} property - The property to increment, for example 'body.velocity.x' or 'angle'.
|
|
|
|
* @param {number} amount - The amount to increment the property by. If child.x = 10 then addAll('x', 40) would make child.x = 50.
|
|
|
|
* @param {boolean} checkAlive - If true the property will only be changed if the child is alive.
|
|
|
|
* @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
|
|
|
|
*/
|
|
|
|
addAll: function (property, amount, checkAlive, checkVisible) {
|
|
|
|
|
|
|
|
this.setAll(property, amount, checkAlive, checkVisible, 1);
|
2013-09-06 14:00:05 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Subtracts the amount from the given property on all children in this Group.
|
|
|
|
* Group.subAll('x', 10) will minus 10 from the child.x value.
|
|
|
|
*
|
|
|
|
* @method subAll
|
|
|
|
* @param {string} property - The property to decrement, for example 'body.velocity.x' or 'angle'.
|
|
|
|
* @param {number} amount - The amount to subtract from the property. If child.x = 50 then subAll('x', 40) would make child.x = 10.
|
|
|
|
* @param {boolean} checkAlive - If true the property will only be changed if the child is alive.
|
|
|
|
* @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
|
|
|
|
*/
|
|
|
|
subAll: function (property, amount, checkAlive, checkVisible) {
|
|
|
|
|
|
|
|
this.setAll(property, amount, checkAlive, checkVisible, 2);
|
2013-09-06 14:00:05 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Multiplies the given property by the amount on all children in this Group.
|
|
|
|
* Group.multiplyAll('x', 2) will x2 the child.x value.
|
|
|
|
*
|
|
|
|
* @method multiplyAll
|
|
|
|
* @param {string} property - The property to multiply, for example 'body.velocity.x' or 'angle'.
|
|
|
|
* @param {number} amount - The amount to multiply the property by. If child.x = 10 then multiplyAll('x', 2) would make child.x = 20.
|
|
|
|
* @param {boolean} checkAlive - If true the property will only be changed if the child is alive.
|
|
|
|
* @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
|
|
|
|
*/
|
|
|
|
multiplyAll: function (property, amount, checkAlive, checkVisible) {
|
|
|
|
|
|
|
|
this.setAll(property, amount, checkAlive, checkVisible, 3);
|
2013-09-06 14:00:05 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Divides the given property by the amount on all children in this Group.
|
|
|
|
* Group.divideAll('x', 2) will half the child.x value.
|
|
|
|
*
|
|
|
|
* @method divideAll
|
|
|
|
* @param {string} property - The property to divide, for example 'body.velocity.x' or 'angle'.
|
|
|
|
* @param {number} amount - The amount to divide the property by. If child.x = 100 then divideAll('x', 2) would make child.x = 50.
|
|
|
|
* @param {boolean} checkAlive - If true the property will only be changed if the child is alive.
|
|
|
|
* @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
|
|
|
|
*/
|
|
|
|
divideAll: function (property, amount, checkAlive, checkVisible) {
|
|
|
|
|
|
|
|
this.setAll(property, amount, checkAlive, checkVisible, 4);
|
2013-09-06 14:00:05 +00:00
|
|
|
|
2013-09-05 20:07:44 +00:00
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Calls a function on all of the children that have exists=true in this Group.
|
|
|
|
* After the existsValue parameter you can add as many parameters as you like, which will all be passed to the child callback.
|
|
|
|
*
|
|
|
|
* @method callAllExists
|
|
|
|
* @param {function} callback - The function that exists on the children that will be called.
|
|
|
|
* @param {boolean} existsValue - Only children with exists=existsValue will be called.
|
|
|
|
* @param {...*} parameter - Additional parameters that will be passed to the callback.
|
|
|
|
*/
|
|
|
|
callAllExists: function (callback, existsValue) {
|
2013-09-20 12:55:33 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
var args = Array.prototype.splice.call(arguments, 2);
|
2013-09-20 12:55:33 +00:00
|
|
|
|
|
|
|
if (this._container.children.length > 0 && this._container.first._iNext)
|
|
|
|
{
|
|
|
|
var currentNode = this._container.first._iNext;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (currentNode.exists == existsValue && currentNode[callback])
|
|
|
|
{
|
|
|
|
currentNode[callback].apply(currentNode, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
currentNode = currentNode._iNext;
|
|
|
|
}
|
|
|
|
while (currentNode != this._container.last._iNext)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-06 19:20:58 +00:00
|
|
|
/**
|
2013-09-20 12:55:33 +00:00
|
|
|
* Calls a function on all of the children regardless if they are dead or alive (see callAllExists if you need control over that)
|
2013-10-01 12:54:29 +00:00
|
|
|
* After the callback parameter you can add as many extra parameters as you like, which will all be passed to the child.
|
|
|
|
*
|
|
|
|
* @method callAll
|
|
|
|
* @param {function} callback - The function that exists on the children that will be called.
|
|
|
|
* @param {...*} parameter - Additional parameters that will be passed to the callback.
|
2013-09-06 19:20:58 +00:00
|
|
|
*/
|
2013-10-01 01:19:08 +00:00
|
|
|
callAll: function (callback) {
|
2013-09-06 19:20:58 +00:00
|
|
|
|
2013-10-01 01:19:08 +00:00
|
|
|
var args = Array.prototype.splice.call(arguments, 1);
|
2013-09-06 19:20:58 +00:00
|
|
|
|
2013-09-14 23:14:45 +00:00
|
|
|
if (this._container.children.length > 0 && this._container.first._iNext)
|
2013-09-06 19:20:58 +00:00
|
|
|
{
|
|
|
|
var currentNode = this._container.first._iNext;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2013-09-20 12:55:33 +00:00
|
|
|
if (currentNode[callback])
|
2013-09-06 19:20:58 +00:00
|
|
|
{
|
|
|
|
currentNode[callback].apply(currentNode, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
currentNode = currentNode._iNext;
|
|
|
|
}
|
|
|
|
while (currentNode != this._container.last._iNext)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-09-05 20:07:44 +00:00
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
* After the checkExists parameter you can add as many parameters as you like, which will all be passed to the callback along with the child.
|
|
|
|
*
|
|
|
|
* @method forEach
|
|
|
|
* @param {Description} callback - Description.
|
|
|
|
* @param {Description} callbackContext - Description.
|
|
|
|
* @param {bool} checkExists - Description.
|
|
|
|
*/
|
2013-09-06 19:20:58 +00:00
|
|
|
forEach: function (callback, callbackContext, checkExists) {
|
|
|
|
|
2013-10-01 01:19:08 +00:00
|
|
|
if (typeof checkExists === 'undefined')
|
|
|
|
{
|
|
|
|
checkExists = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var args = Array.prototype.splice.call(arguments, 3);
|
|
|
|
args.unshift(null);
|
2013-09-06 19:20:58 +00:00
|
|
|
|
2013-09-14 23:14:45 +00:00
|
|
|
if (this._container.children.length > 0 && this._container.first._iNext)
|
2013-09-06 19:20:58 +00:00
|
|
|
{
|
|
|
|
var currentNode = this._container.first._iNext;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (checkExists == false || (checkExists && currentNode.exists))
|
|
|
|
{
|
2013-10-01 01:19:08 +00:00
|
|
|
args[0] = currentNode;
|
|
|
|
callback.apply(callbackContext, args);
|
2013-09-06 19:20:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
currentNode = currentNode._iNext;
|
|
|
|
}
|
|
|
|
while (currentNode != this._container.last._iNext);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-09-05 20:07:44 +00:00
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method forEachAlive
|
|
|
|
* @param {Description} callback - Description.
|
|
|
|
* @param {Description} callbackContext - Description.
|
|
|
|
*/
|
2013-09-12 15:18:44 +00:00
|
|
|
forEachAlive: function (callback, callbackContext) {
|
2013-09-06 19:20:58 +00:00
|
|
|
|
2013-10-01 01:19:08 +00:00
|
|
|
var args = Array.prototype.splice.call(arguments, 2);
|
|
|
|
args.unshift(null);
|
|
|
|
|
2013-09-14 23:14:45 +00:00
|
|
|
if (this._container.children.length > 0 && this._container.first._iNext)
|
2013-09-06 19:20:58 +00:00
|
|
|
{
|
|
|
|
var currentNode = this._container.first._iNext;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (currentNode.alive)
|
|
|
|
{
|
2013-10-01 01:19:08 +00:00
|
|
|
args[0] = currentNode;
|
|
|
|
callback.apply(callbackContext, args);
|
2013-09-06 19:20:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
currentNode = currentNode._iNext;
|
|
|
|
}
|
|
|
|
while (currentNode != this._container.last._iNext);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-09-05 20:07:44 +00:00
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method forEachDead
|
|
|
|
* @param {Description} callback - Description.
|
|
|
|
* @param {Description} callbackContext - Description.
|
|
|
|
*/
|
2013-09-12 15:18:44 +00:00
|
|
|
forEachDead: function (callback, callbackContext) {
|
2013-09-06 19:20:58 +00:00
|
|
|
|
2013-10-01 01:19:08 +00:00
|
|
|
var args = Array.prototype.splice.call(arguments, 2);
|
|
|
|
args.unshift(null);
|
|
|
|
|
2013-09-14 23:14:45 +00:00
|
|
|
if (this._container.children.length > 0 && this._container.first._iNext)
|
2013-09-06 19:20:58 +00:00
|
|
|
{
|
|
|
|
var currentNode = this._container.first._iNext;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (currentNode.alive == false)
|
|
|
|
{
|
2013-10-01 01:19:08 +00:00
|
|
|
args[0] = currentNode;
|
|
|
|
callback.apply(callbackContext, args);
|
2013-09-06 19:20:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
currentNode = currentNode._iNext;
|
|
|
|
}
|
|
|
|
while (currentNode != this._container.last._iNext);
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this function to retrieve the first object with exists == (the given state) in the group.
|
|
|
|
*
|
2013-10-01 12:54:29 +00:00
|
|
|
* @method getFirstExists
|
|
|
|
* @param {Description} state - Description.
|
2013-09-06 19:20:58 +00:00
|
|
|
* @return {Any} The first child, or null if none found.
|
|
|
|
*/
|
|
|
|
getFirstExists: function (state) {
|
|
|
|
|
2013-09-10 00:26:50 +00:00
|
|
|
if (typeof state !== 'boolean')
|
|
|
|
{
|
|
|
|
state = true;
|
|
|
|
}
|
2013-09-06 19:20:58 +00:00
|
|
|
|
2013-09-14 23:14:45 +00:00
|
|
|
if (this._container.children.length > 0 && this._container.first._iNext)
|
2013-09-06 19:20:58 +00:00
|
|
|
{
|
|
|
|
var currentNode = this._container.first._iNext;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2013-09-10 00:26:50 +00:00
|
|
|
if (currentNode.exists === state)
|
2013-09-06 19:20:58 +00:00
|
|
|
{
|
|
|
|
return currentNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
currentNode = currentNode._iNext;
|
|
|
|
}
|
|
|
|
while (currentNode != this._container.last._iNext);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
2013-09-05 20:07:44 +00:00
|
|
|
},
|
|
|
|
|
2013-09-06 14:00:05 +00:00
|
|
|
/**
|
|
|
|
* Call this function to retrieve the first object with alive == true in the group.
|
|
|
|
* This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
|
|
|
|
*
|
2013-10-01 12:54:29 +00:00
|
|
|
* @method getFirstAlive
|
2013-09-06 14:00:05 +00:00
|
|
|
* @return {Any} The first alive child, or null if none found.
|
|
|
|
*/
|
2013-09-05 20:07:44 +00:00
|
|
|
getFirstAlive: function () {
|
|
|
|
|
2013-09-14 23:14:45 +00:00
|
|
|
if (this._container.children.length > 0 && this._container.first._iNext)
|
2013-09-05 20:07:44 +00:00
|
|
|
{
|
2013-09-06 19:20:58 +00:00
|
|
|
var currentNode = this._container.first._iNext;
|
|
|
|
|
|
|
|
do
|
2013-09-05 20:07:44 +00:00
|
|
|
{
|
2013-09-06 19:20:58 +00:00
|
|
|
if (currentNode.alive)
|
|
|
|
{
|
|
|
|
return currentNode;
|
|
|
|
}
|
2013-09-05 20:07:44 +00:00
|
|
|
|
2013-09-06 19:20:58 +00:00
|
|
|
currentNode = currentNode._iNext;
|
|
|
|
}
|
|
|
|
while (currentNode != this._container.last._iNext);
|
2013-09-05 20:07:44 +00:00
|
|
|
}
|
2013-09-06 14:00:05 +00:00
|
|
|
|
|
|
|
return null;
|
2013-09-05 20:07:44 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-06 14:00:05 +00:00
|
|
|
/**
|
|
|
|
* Call this function to retrieve the first object with alive == false in the group.
|
|
|
|
* This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
|
|
|
|
*
|
2013-10-01 12:54:29 +00:00
|
|
|
* @method getFirstDead
|
2013-09-06 14:00:05 +00:00
|
|
|
* @return {Any} The first dead child, or null if none found.
|
|
|
|
*/
|
2013-09-05 20:07:44 +00:00
|
|
|
getFirstDead: function () {
|
|
|
|
|
2013-09-14 23:14:45 +00:00
|
|
|
if (this._container.children.length > 0 && this._container.first._iNext)
|
2013-09-05 20:07:44 +00:00
|
|
|
{
|
2013-09-06 19:20:58 +00:00
|
|
|
var currentNode = this._container.first._iNext;
|
|
|
|
|
|
|
|
do
|
2013-09-05 20:07:44 +00:00
|
|
|
{
|
2013-09-06 19:20:58 +00:00
|
|
|
if (!currentNode.alive)
|
|
|
|
{
|
|
|
|
return currentNode;
|
|
|
|
}
|
2013-09-05 20:07:44 +00:00
|
|
|
|
2013-09-06 19:20:58 +00:00
|
|
|
currentNode = currentNode._iNext;
|
|
|
|
}
|
|
|
|
while (currentNode != this._container.last._iNext);
|
2013-09-05 20:07:44 +00:00
|
|
|
}
|
2013-09-06 14:00:05 +00:00
|
|
|
|
|
|
|
return null;
|
2013-09-05 20:07:44 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-06 14:00:05 +00:00
|
|
|
/**
|
|
|
|
* Call this function to find out how many members of the group are alive.
|
|
|
|
*
|
2013-10-01 12:54:29 +00:00
|
|
|
* @method countLiving
|
2013-09-06 14:00:05 +00:00
|
|
|
* @return {number} The number of children flagged as alive. Returns -1 if Group is empty.
|
|
|
|
*/
|
|
|
|
countLiving: function () {
|
2013-09-05 20:07:44 +00:00
|
|
|
|
2013-09-06 14:00:05 +00:00
|
|
|
var total = -1;
|
2013-09-06 19:20:58 +00:00
|
|
|
|
2013-09-14 23:14:45 +00:00
|
|
|
if (this._container.children.length > 0 && this._container.first._iNext)
|
2013-09-05 20:07:44 +00:00
|
|
|
{
|
2013-09-06 19:20:58 +00:00
|
|
|
var currentNode = this._container.first._iNext;
|
|
|
|
|
|
|
|
do
|
2013-09-05 20:07:44 +00:00
|
|
|
{
|
2013-09-06 19:20:58 +00:00
|
|
|
if (currentNode.alive)
|
|
|
|
{
|
|
|
|
total++;
|
|
|
|
}
|
2013-09-05 20:07:44 +00:00
|
|
|
|
2013-09-06 19:20:58 +00:00
|
|
|
currentNode = currentNode._iNext;
|
|
|
|
}
|
|
|
|
while (currentNode != this._container.last._iNext);
|
2013-09-05 20:07:44 +00:00
|
|
|
}
|
|
|
|
|
2013-09-06 14:00:05 +00:00
|
|
|
return total;
|
2013-09-05 20:07:44 +00:00
|
|
|
|
2013-09-06 14:00:05 +00:00
|
|
|
},
|
2013-09-05 20:07:44 +00:00
|
|
|
|
2013-09-06 14:00:05 +00:00
|
|
|
/**
|
|
|
|
* Call this function to find out how many members of the group are dead.
|
|
|
|
*
|
2013-10-01 12:54:29 +00:00
|
|
|
* @method countDead
|
2013-09-06 14:00:05 +00:00
|
|
|
* @return {number} The number of children flagged as dead. Returns -1 if Group is empty.
|
|
|
|
*/
|
|
|
|
countDead: function () {
|
|
|
|
|
|
|
|
var total = -1;
|
2013-09-06 19:20:58 +00:00
|
|
|
|
2013-09-14 23:14:45 +00:00
|
|
|
if (this._container.children.length > 0 && this._container.first._iNext)
|
2013-09-05 20:07:44 +00:00
|
|
|
{
|
2013-09-06 19:20:58 +00:00
|
|
|
var currentNode = this._container.first._iNext;
|
|
|
|
|
|
|
|
do
|
2013-09-05 20:07:44 +00:00
|
|
|
{
|
2013-09-06 19:20:58 +00:00
|
|
|
if (!currentNode.alive)
|
|
|
|
{
|
|
|
|
total++;
|
|
|
|
}
|
2013-09-05 20:07:44 +00:00
|
|
|
|
2013-09-06 19:20:58 +00:00
|
|
|
currentNode = currentNode._iNext;
|
|
|
|
}
|
|
|
|
while (currentNode != this._container.last._iNext);
|
2013-09-05 20:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return total;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-06 14:00:05 +00:00
|
|
|
/**
|
|
|
|
* Returns a member at random from the group.
|
|
|
|
*
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {number} startIndex - Optional offset off the front of the array. Default value is 0, or the beginning of the array.
|
|
|
|
* @param {number} length - Optional restriction on the number of values you want to randomly select from.
|
2013-09-06 14:00:05 +00:00
|
|
|
* @return {Any} A random child of this Group.
|
|
|
|
*/
|
|
|
|
getRandom: function (startIndex, length) {
|
|
|
|
|
2013-09-14 23:14:45 +00:00
|
|
|
if (this._container.children.length == 0)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-09-06 14:00:05 +00:00
|
|
|
startIndex = startIndex || 0;
|
|
|
|
length = length || this._container.children.length;
|
|
|
|
|
|
|
|
return this.game.math.getRandom(this._container.children, startIndex, length);
|
2013-09-05 20:07:44 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method remove
|
|
|
|
* @param {Description} child - Description.
|
|
|
|
*/
|
2013-09-05 20:07:44 +00:00
|
|
|
remove: function (child) {
|
2013-09-06 19:20:58 +00:00
|
|
|
|
2013-09-09 12:29:33 +00:00
|
|
|
child.events.onRemovedFromGroup.dispatch(child, this);
|
2013-09-06 19:20:58 +00:00
|
|
|
this._container.removeChild(child);
|
2013-09-10 11:46:14 +00:00
|
|
|
child.group = null;
|
2013-09-06 19:20:58 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method removeAll
|
|
|
|
*/
|
2013-09-06 19:20:58 +00:00
|
|
|
removeAll: function () {
|
|
|
|
|
2013-09-13 04:44:04 +00:00
|
|
|
if (this._container.children.length == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-06 19:20:58 +00:00
|
|
|
do
|
|
|
|
{
|
2013-09-13 04:44:04 +00:00
|
|
|
if (this._container.children[0].events)
|
|
|
|
{
|
|
|
|
this._container.children[0].events.onRemovedFromGroup.dispatch(this._container.children[0], this);
|
|
|
|
}
|
2013-09-06 19:20:58 +00:00
|
|
|
this._container.removeChild(this._container.children[0]);
|
|
|
|
}
|
|
|
|
while (this._container.children.length > 0);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method removeBetween
|
|
|
|
* @param {Description} startIndex - Description.
|
|
|
|
* @param {Description} endIndex - Description.
|
|
|
|
*/
|
2013-09-06 19:20:58 +00:00
|
|
|
removeBetween: function (startIndex, endIndex) {
|
|
|
|
|
2013-09-14 23:14:45 +00:00
|
|
|
if (this._container.children.length == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-06 19:20:58 +00:00
|
|
|
if (startIndex > endIndex || startIndex < 0 || endIndex > this._container.children.length)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = startIndex; i < endIndex; i++)
|
|
|
|
{
|
|
|
|
var child = this._container.children[i];
|
2013-09-09 12:29:33 +00:00
|
|
|
child.events.onRemovedFromGroup.dispatch(child, this);
|
2013-09-06 19:20:58 +00:00
|
|
|
this._container.removeChild(child);
|
|
|
|
}
|
|
|
|
|
2013-09-05 20:07:44 +00:00
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method destroy
|
|
|
|
*/
|
2013-09-05 20:07:44 +00:00
|
|
|
destroy: function () {
|
2013-09-06 19:20:58 +00:00
|
|
|
|
|
|
|
this.removeAll();
|
|
|
|
|
|
|
|
this._container.parent.removeChild(this._container);
|
|
|
|
|
|
|
|
this._container = null;
|
|
|
|
|
|
|
|
this.game = null;
|
|
|
|
|
|
|
|
this.exists = false;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method dump
|
|
|
|
*/
|
2013-09-10 11:46:14 +00:00
|
|
|
dump: function (full) {
|
|
|
|
|
|
|
|
if (typeof full == 'undefined')
|
|
|
|
{
|
|
|
|
full = false;
|
|
|
|
}
|
2013-09-06 19:20:58 +00:00
|
|
|
|
2013-09-10 11:46:14 +00:00
|
|
|
var spacing = 20;
|
|
|
|
var output = "\n" + Phaser.Utils.pad('Node', spacing) + "|" + Phaser.Utils.pad('Next', spacing) + "|" + Phaser.Utils.pad('Previous', spacing) + "|" + Phaser.Utils.pad('First', spacing) + "|" + Phaser.Utils.pad('Last', spacing);
|
2013-09-06 19:20:58 +00:00
|
|
|
|
2013-09-10 11:46:14 +00:00
|
|
|
console.log(output);
|
2013-09-06 19:20:58 +00:00
|
|
|
|
2013-09-10 11:46:14 +00:00
|
|
|
var output = Phaser.Utils.pad('----------', spacing) + "|" + Phaser.Utils.pad('----------', spacing) + "|" + Phaser.Utils.pad('----------', spacing) + "|" + Phaser.Utils.pad('----------', spacing) + "|" + Phaser.Utils.pad('----------', spacing);
|
|
|
|
console.log(output);
|
|
|
|
|
|
|
|
if (full)
|
|
|
|
{
|
|
|
|
var testObject = this.game.stage._stage.last._iNext;
|
|
|
|
var displayObject = this.game.stage._stage;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var testObject = this._container.last._iNext;
|
|
|
|
var displayObject = this._container;
|
|
|
|
}
|
2013-09-06 19:20:58 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
var name = displayObject.name || '*';
|
|
|
|
var nameNext = '-';
|
|
|
|
var namePrev = '-';
|
|
|
|
var nameFirst = '-';
|
|
|
|
var nameLast = '-';
|
|
|
|
|
|
|
|
if (displayObject._iNext)
|
|
|
|
{
|
|
|
|
nameNext = displayObject._iNext.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (displayObject._iPrev)
|
|
|
|
{
|
|
|
|
namePrev = displayObject._iPrev.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (displayObject.first)
|
|
|
|
{
|
|
|
|
nameFirst = displayObject.first.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (displayObject.last)
|
|
|
|
{
|
|
|
|
nameLast = displayObject.last.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof nameNext === 'undefined')
|
|
|
|
{
|
|
|
|
nameNext = '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof namePrev === 'undefined')
|
|
|
|
{
|
|
|
|
namePrev = '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof nameFirst === 'undefined')
|
|
|
|
{
|
|
|
|
nameFirst = '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof nameLast === 'undefined')
|
|
|
|
{
|
|
|
|
nameLast = '-';
|
|
|
|
}
|
|
|
|
|
2013-09-10 11:46:14 +00:00
|
|
|
var output = Phaser.Utils.pad(name, spacing) + "|" + Phaser.Utils.pad(nameNext, spacing) + "|" + Phaser.Utils.pad(namePrev, spacing) + "|" + Phaser.Utils.pad(nameFirst, spacing) + "|" + Phaser.Utils.pad(nameLast, spacing);
|
|
|
|
console.log(output);
|
2013-09-06 19:20:58 +00:00
|
|
|
|
|
|
|
displayObject = displayObject._iNext;
|
|
|
|
|
|
|
|
}
|
|
|
|
while(displayObject != testObject)
|
|
|
|
|
2013-09-05 20:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get
|
|
|
|
* @return {Description}
|
|
|
|
*/
|
2013-09-19 03:45:08 +00:00
|
|
|
Object.defineProperty(Phaser.Group.prototype, "length", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
return this._container.children.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Get
|
|
|
|
* @return {Description}
|
|
|
|
*//**
|
|
|
|
* Set
|
|
|
|
* @param {Description} value - Description
|
|
|
|
*/
|
2013-09-06 14:00:05 +00:00
|
|
|
Object.defineProperty(Phaser.Group.prototype, "x", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
return this._container.position.x;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
this._container.position.x = value;
|
2013-09-11 12:21:07 +00:00
|
|
|
}
|
2013-09-06 14:00:05 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Get
|
|
|
|
* @return {Description}
|
|
|
|
*//**
|
|
|
|
* Set
|
|
|
|
* @param {Description} value - Description
|
|
|
|
*/
|
2013-09-06 14:00:05 +00:00
|
|
|
Object.defineProperty(Phaser.Group.prototype, "y", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
return this._container.position.y;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
this._container.position.y = value;
|
2013-09-11 12:21:07 +00:00
|
|
|
}
|
2013-09-06 14:00:05 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Get
|
|
|
|
* @return {Description}
|
|
|
|
*//**
|
|
|
|
* Set
|
|
|
|
* @param {Description} value - Description
|
|
|
|
*/
|
2013-09-06 14:00:05 +00:00
|
|
|
Object.defineProperty(Phaser.Group.prototype, "angle", {
|
|
|
|
|
|
|
|
get: function() {
|
|
|
|
return Phaser.Math.radToDeg(this._container.rotation);
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function(value) {
|
|
|
|
this._container.rotation = Phaser.Math.degToRad(value);
|
2013-09-11 12:21:07 +00:00
|
|
|
}
|
2013-09-06 14:00:05 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Get
|
|
|
|
* @return {Description}
|
|
|
|
*//**
|
|
|
|
* Set
|
|
|
|
* @param {Description} value - Description
|
|
|
|
*/
|
2013-09-06 14:00:05 +00:00
|
|
|
Object.defineProperty(Phaser.Group.prototype, "rotation", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
return this._container.rotation;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
this._container.rotation = value;
|
2013-09-11 12:21:07 +00:00
|
|
|
}
|
2013-09-06 14:00:05 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Get
|
|
|
|
* @return {Description}
|
|
|
|
*//**
|
|
|
|
* Set
|
|
|
|
* @param {Description} value - Description.
|
|
|
|
*/
|
2013-09-06 14:00:05 +00:00
|
|
|
Object.defineProperty(Phaser.Group.prototype, "visible", {
|
2013-09-05 20:07:44 +00:00
|
|
|
|
|
|
|
get: function () {
|
|
|
|
return this._container.visible;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
this._container.visible = value;
|
2013-09-11 12:21:07 +00:00
|
|
|
}
|
2013-09-05 20:07:44 +00:00
|
|
|
|
|
|
|
});
|