phaser/docs/Group.js.html

1686 lines
48 KiB
HTML
Raw Normal View History

2013-10-02 00:16:40 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Phaser Source: core/Group.js</title>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
<link type="text/css" rel="stylesheet" href="styles/site.cerulean.css">
</head>
<body>
<div class="container-fluid">
<div class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<a class="brand" href="index.html">Phaser</a>
<ul class="nav">
<li class="dropdown">
<a href="namespaces.list.html" class="dropdown-toggle" data-toggle="dropdown">Namespaces<b
2013-10-02 00:16:40 +00:00
class="caret"></b></a>
<ul class="dropdown-menu ">
<li>
<a href="Phaser.html">Phaser</a>
2013-10-02 00:16:40 +00:00
</li>
</ul>
</li>
<li class="dropdown">
<a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b
class="caret"></b></a>
<ul class="dropdown-menu ">
<li>
<a href="Phaser.Animation.html">Animation</a>
</li>
<li>
<a href="Phaser.AnimationManager.html">AnimationManager</a>
2013-10-02 00:16:40 +00:00
</li>
<li>
<a href="Phaser.AnimationParser.html">AnimationParser</a>
2013-10-02 00:16:40 +00:00
</li>
2013-11-28 15:57:09 +00:00
<li>
<a href="Phaser.BitmapData.html">BitmapData</a>
</li>
2013-10-25 15:54:40 +00:00
<li>
<a href="Phaser.BitmapText.html">BitmapText</a>
</li>
<li>
<a href="Phaser.Button.html">Button</a>
</li>
2013-10-02 00:16:40 +00:00
<li>
<a href="Phaser.Cache.html">Cache</a>
2013-10-02 00:16:40 +00:00
</li>
<li>
<a href="Phaser.Camera.html">Camera</a>
2013-10-02 00:16:40 +00:00
</li>
2013-10-02 14:05:55 +00:00
<li>
<a href="Phaser.Canvas.html">Canvas</a>
2013-10-02 14:05:55 +00:00
</li>
2013-10-02 00:16:40 +00:00
<li>
<a href="Phaser.Circle.html">Circle</a>
2013-10-02 00:16:40 +00:00
</li>
2013-10-03 00:21:08 +00:00
<li>
<a href="Phaser.Color.html">Color</a>
2013-10-03 00:21:08 +00:00
</li>
2013-10-02 11:11:22 +00:00
<li>
<a href="Phaser.Device.html">Device</a>
2013-10-02 11:11:22 +00:00
</li>
2014-02-05 06:29:17 +00:00
<li>
<a href="Phaser.DOMSprite.html">DOMSprite</a>
</li>
2013-10-03 00:21:08 +00:00
<li>
<a href="Phaser.Easing.html">Easing</a>
</li>
<li>
<a href="Phaser.Easing.Back.html">Back</a>
</li>
<li>
<a href="Phaser.Easing.Bounce.html">Bounce</a>
</li>
<li>
<a href="Phaser.Easing.Circular.html">Circular</a>
</li>
<li>
<a href="Phaser.Easing.Cubic.html">Cubic</a>
</li>
<li>
<a href="Phaser.Easing.Elastic.html">Elastic</a>
</li>
<li>
<a href="Phaser.Easing.Exponential.html">Exponential</a>
</li>
<li>
<a href="Phaser.Easing.Linear.html">Linear</a>
</li>
<li>
<a href="Phaser.Easing.Quadratic.html">Quadratic</a>
</li>
<li>
<a href="Phaser.Easing.Quartic.html">Quartic</a>
</li>
<li>
<a href="Phaser.Easing.Quintic.html">Quintic</a>
</li>
<li>
<a href="Phaser.Easing.Sinusoidal.html">Sinusoidal</a>
</li>
2013-10-25 15:54:40 +00:00
<li>
<a href="Phaser.Events.html">Events</a>
</li>
2013-11-28 15:57:09 +00:00
<li>
<a href="Phaser.Filter.html">Filter</a>
</li>
<li>
<a href="Phaser.Frame.html">Frame</a>
</li>
<li>
<a href="Phaser.FrameData.html">FrameData</a>
2013-10-03 00:21:08 +00:00
</li>
2013-10-02 00:16:40 +00:00
<li>
<a href="Phaser.Game.html">Game</a>
</li>
2013-10-25 15:54:40 +00:00
<li>
<a href="Phaser.GameObjectFactory.html">GameObjectFactory</a>
</li>
2014-02-05 06:29:17 +00:00
<li>
<a href="Phaser.Gamepad.html">Gamepad</a>
</li>
<li>
<a href="Phaser.GamepadButton.html">GamepadButton</a>
</li>
2013-10-25 15:54:40 +00:00
<li>
<a href="Phaser.Graphics.html">Graphics</a>
</li>
2013-10-02 00:16:40 +00:00
<li>
<a href="Phaser.Group.html">Group</a>
</li>
<li>
<a href="Phaser.Image.html">Image</a>
</li>
2013-10-02 12:18:58 +00:00
<li>
<a href="Phaser.Input.html">Input</a>
</li>
2013-10-02 14:05:55 +00:00
<li>
<a href="Phaser.InputHandler.html">InputHandler</a>
</li>
<li>
<a href="Phaser.Key.html">Key</a>
</li>
<li>
<a href="Phaser.Keyboard.html">Keyboard</a>
</li>
2014-02-05 06:29:17 +00:00
<li>
<a href="Phaser.Line.html">Line</a>
</li>
2013-10-02 11:11:22 +00:00
<li>
<a href="Phaser.LinkedList.html">LinkedList</a>
</li>
<li>
2013-10-02 14:05:55 +00:00
<a href="Phaser.Loader.html">Loader</a>
</li>
<li>
<a href="Phaser.LoaderParser.html">LoaderParser</a>
2013-10-02 14:05:55 +00:00
</li>
<li>
<a href="Phaser.Math.html">Math</a>
</li>
<li>
<a href="Phaser.Mouse.html">Mouse</a>
</li>
<li>
<a href="Phaser.MSPointer.html">MSPointer</a>
2013-10-02 11:11:22 +00:00
</li>
2013-10-02 19:18:24 +00:00
<li>
<a href="Phaser.Net.html">Net</a>
</li>
<li>
<a href="Phaser.Particles.html">Particles</a>
</li>
<li>
<a href="Phaser.Particles.Arcade.Emitter.html">Emitter</a>
</li>
2013-10-25 15:54:40 +00:00
<li>
<a href="Phaser.Physics.html">Physics</a>
</li>
<li>
<a href="Phaser.Physics.Arcade.html">Arcade</a>
</li>
2013-10-25 16:30:37 +00:00
<li>
<a href="Phaser.Physics.Arcade.Body.html">Body</a>
</li>
2013-10-02 11:11:22 +00:00
<li>
<a href="Phaser.Plugin.html">Plugin</a>
</li>
2013-10-02 14:05:55 +00:00
<li>
<a href="Phaser.PluginManager.html">PluginManager</a>
</li>
2013-10-02 11:11:22 +00:00
<li>
<a href="Phaser.Point.html">Point</a>
</li>
2013-10-02 14:05:55 +00:00
<li>
<a href="Phaser.Pointer.html">Pointer</a>
</li>
<li>
<a href="Phaser.Polygon.html">Polygon</a>
</li>
2013-10-02 14:05:55 +00:00
<li>
<a href="Phaser.QuadTree.html">QuadTree</a>
</li>
<li>
<a href="Phaser.RandomDataGenerator.html">RandomDataGenerator</a>
</li>
2013-10-02 11:11:22 +00:00
<li>
<a href="Phaser.Rectangle.html">Rectangle</a>
</li>
2013-10-25 15:54:40 +00:00
<li>
<a href="Phaser.RenderTexture.html">RenderTexture</a>
</li>
2013-10-03 00:21:08 +00:00
<li>
<a href="Phaser.RequestAnimationFrame.html">RequestAnimationFrame</a>
</li>
2013-10-02 11:11:22 +00:00
<li>
<a href="Phaser.Signal.html">Signal</a>
</li>
2014-02-05 06:29:17 +00:00
<li>
<a href="Phaser.SinglePad.html">SinglePad</a>
</li>
2013-10-03 00:21:08 +00:00
<li>
<a href="Phaser.Sound.html">Sound</a>
</li>
<li>
<a href="Phaser.SoundManager.html">SoundManager</a>
</li>
2013-10-25 15:54:40 +00:00
<li>
<a href="Phaser.Sprite.html">Sprite</a>
</li>
2013-10-02 11:11:22 +00:00
<li>
<a href="Phaser.Stage.html">Stage</a>
</li>
2013-10-03 00:21:08 +00:00
<li>
<a href="Phaser.StageScaleMode.html">StageScaleMode</a>
</li>
2013-10-02 11:11:22 +00:00
<li>
<a href="Phaser.State.html">State</a>
</li>
<li>
<a href="Phaser.StateManager.html">StateManager</a>
</li>
2013-10-25 15:54:40 +00:00
<li>
<a href="Phaser.Text.html">Text</a>
</li>
2013-11-28 15:57:09 +00:00
<li>
<a href="Phaser.Tile.html">Tile</a>
</li>
<li>
<a href="Phaser.Tilemap.html">Tilemap</a>
</li>
<li>
<a href="Phaser.TilemapLayer.html">TilemapLayer</a>
</li>
<li>
<a href="Phaser.TilemapParser.html">TilemapParser</a>
</li>
<li>
<a href="Phaser.Tileset.html">Tileset</a>
</li>
2013-10-25 15:54:40 +00:00
<li>
<a href="Phaser.TileSprite.html">TileSprite</a>
</li>
<li>
<a href="Phaser.Time.html">Time</a>
</li>
2013-11-28 15:57:09 +00:00
<li>
<a href="Phaser.Timer.html">Timer</a>
</li>
2014-02-05 06:29:17 +00:00
<li>
<a href="Phaser.TimerEvent.html">TimerEvent</a>
</li>
2013-10-02 14:05:55 +00:00
<li>
<a href="Phaser.Touch.html">Touch</a>
</li>
<li>
<a href="Phaser.Tween.html">Tween</a>
</li>
<li>
<a href="Phaser.TweenManager.html">TweenManager</a>
</li>
<li>
<a href="Phaser.Utils.html">Utils</a>
</li>
<li>
<a href="Phaser.Utils.Debug.html">Debug</a>
</li>
2013-10-02 11:11:22 +00:00
<li>
<a href="Phaser.World.html">World</a>
</li>
<li>
<a href="SignalBinding.html">SignalBinding</a>
</li>
2013-10-02 00:16:40 +00:00
</ul>
</li>
<li class="dropdown">
<a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b
class="caret"></b></a>
<ul class="dropdown-menu ">
<li>
<a href="global.html#canUseNewCanvasBlendModes">canUseNewCanvasBlendModes</a>
</li>
<li>
<a href="global.html#getNextPowerOfTwo">getNextPowerOfTwo</a>
</li>
<li>
<a href="global.html#hex2rgb">hex2rgb</a>
</li>
<li>
<a href="global.html#hitTest">hitTest</a>
</li>
<li>
<a href="global.html#rgb2hex">rgb2hex</a>
</li>
</ul>
</li>
2013-10-02 00:16:40 +00:00
</ul>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<div id="main">
<h1 class="page-title">Source: core/Group.js</h1>
<section>
<article>
<pre class="sunlight-highlight-javascript linenums">/**
* @author Richard Davey &lt;rich@photonstorm.com>
2014-02-05 06:29:17 +00:00
* @copyright 2014 Photon Storm Ltd.
2013-10-02 00:16:40 +00:00
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* Phaser Group constructor.
* @class Phaser.Group
* @classdesc A Group is a container for display objects that allows for fast pooling, recycling and collision checks.
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
* @param {*} parent - The parent Group, DisplayObject or DisplayObjectContainer that this Group will be added to. If undefined or null it will use game.world.
2013-10-02 10:22:20 +00:00
* @param {string} [name=group] - A name for this Group. Not used internally but useful for debugging.
* @param {boolean} [useStage=false] - Should this Group be added to the World (default, false) or direct to the Stage (true).
2013-10-02 00:16:40 +00:00
*/
Phaser.Group = function (game, parent, name, useStage) {
2013-11-28 15:57:09 +00:00
/**
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = game;
2014-02-05 06:29:17 +00:00
if (typeof parent === 'undefined' || parent === null)
2014-02-05 06:29:17 +00:00
{
parent = game.world;
}
2013-11-28 15:57:09 +00:00
/**
* @property {string} name - A name for this Group. Not used internally but useful for debugging.
*/
this.name = name || 'group';
2013-10-02 00:16:40 +00:00
PIXI.DisplayObjectContainer.call(this);
2014-02-05 06:29:17 +00:00
if (typeof useStage === 'undefined')
2013-11-28 15:57:09 +00:00
{
if (parent)
{
parent.addChild(this);
2013-11-28 15:57:09 +00:00
}
else
{
this.game.stage._stage.addChild(this);
2013-11-28 15:57:09 +00:00
}
}
else
{
this.game.stage._stage.addChild(this);
}
2013-10-02 00:16:40 +00:00
/**
2013-11-28 15:57:09 +00:00
* @property {number} type - Internal Phaser Type value.
* @protected
*/
this.type = Phaser.GROUP;
2014-02-05 06:29:17 +00:00
/**
* @property {boolean} alive - The alive property is useful for Groups that are children of other Groups and need to be included/excluded in checks like forEachAlive.
* @default
*/
this.alive = true;
2013-10-02 00:16:40 +00:00
/**
* @property {boolean} exists - If exists is true the Group is updated, otherwise it is skipped.
2013-11-28 15:57:09 +00:00
* @default
*/
this.exists = true;
/**
* @property {Phaser.Group|Phaser.Sprite} parent - The parent of this Group.
2014-02-05 06:29:17 +00:00
*/
// this.group = null;
2014-02-05 06:29:17 +00:00
/**
* @property {Phaser.Point} scale - The scale of the Group container.
2013-11-28 15:57:09 +00:00
*/
this.scale = new Phaser.Point(1, 1);
2014-02-05 06:29:17 +00:00
/**
* @property {Phaser.Point} pivot - The pivot point of the Group container.
*/
2013-11-01 18:16:52 +00:00
/**
* The cursor is a simple way to iterate through the objects in a Group using the Group.next and Group.previous functions.
* The cursor is set to the first child added to the Group and doesn't change unless you call next, previous or set it directly with Group.cursor.
* @property {any} cursor - The current display object that the Group cursor is pointing to.
2013-11-28 15:57:09 +00:00
*/
2013-11-01 18:16:52 +00:00
this.cursor = null;
this._cursorIndex = 0;
2013-10-02 00:16:40 +00:00
};
Phaser.Group.prototype = Object.create(PIXI.DisplayObjectContainer.prototype);
Phaser.Group.prototype.constructor = Phaser.Group;
/**
* @constant
* @type {number}
*/
Phaser.Group.RETURN_NONE = 0;
/**
* @constant
* @type {number}
*/
Phaser.Group.RETURN_TOTAL = 1;
/**
* @constant
* @type {number}
*/
Phaser.Group.RETURN_CHILD = 2;
/**
* @constant
* @type {number}
*/
Phaser.Group.SORT_ASCENDING = -1;
/**
* @constant
* @type {number}
*/
Phaser.Group.SORT_DESCENDING = 1;
// PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index)
2013-10-02 00:16:40 +00:00
/**
* Adds an existing object to this Group. The object can be an instance of Phaser.Sprite, Phaser.Button or any other display object.
* The child is automatically added to the top of the Group, so renders on-top of everything else within the Group. If you need to control
* that then see the addAt method.
*
* @see Phaser.Group#create
* @see Phaser.Group#addAt
* @method Phaser.Group#add
* @param {*} child - An instance of Phaser.Sprite, Phaser.Button or any other display object..
* @return {*} The child that was added to the Group.
*/
Phaser.Group.prototype.add = function (child) {
if (child.parent !== this)
{
this.addChild(child);
2013-10-02 00:16:40 +00:00
if (child.events)
2013-11-28 15:57:09 +00:00
{
child.events.onAddedToGroup.dispatch(child, this);
}
}
2014-02-05 06:29:17 +00:00
if (this.cursor === null)
{
this.cursor = child;
}
2014-02-05 06:29:17 +00:00
return child;
2013-10-02 00:16:40 +00:00
}
2013-10-25 15:54:40 +00:00
/**
* Adds an existing object to this Group. The object can be an instance of Phaser.Sprite, Phaser.Button or any other display object.
* The child is added to the Group at the location specified by the index value, this allows you to control child ordering.
*
* @method Phaser.Group#addAt
* @param {*} child - An instance of Phaser.Sprite, Phaser.Button or any other display object..
* @param {number} index - The index within the Group to insert the child to.
* @return {*} The child that was added to the Group.
*/
Phaser.Group.prototype.addAt = function (child, index) {
2014-02-05 06:29:17 +00:00
if (child.parent !== this)
{
this.addChildAt(child, index);
2013-11-01 18:16:52 +00:00
if (child.events)
{
child.events.onAddedToGroup.dispatch(child, this);
2013-11-28 15:57:09 +00:00
}
}
2013-10-02 00:16:40 +00:00
if (this.cursor === null)
{
this.cursor = child;
}
2013-10-02 00:16:40 +00:00
return child;
2013-10-02 00:16:40 +00:00
}
2014-02-05 06:29:17 +00:00
/**
* Returns the child found at the given index within this Group.
*
* @method Phaser.Group#getAt
* @param {number} index - The index to return the child from.
* @return {*} The child that was found at the given index.
*/
Phaser.Group.prototype.getAt = function (index) {
2014-02-05 06:29:17 +00:00
return this.getChildAt(index);
2013-10-02 00:16:40 +00:00
}
2013-10-25 15:54:40 +00:00
/**
* Automatically creates a new Phaser.Sprite object and adds it to the top of this Group.
* Useful if you don't need to create the Sprite instances before-hand.
*
* @method Phaser.Group#create
* @param {number} x - The x coordinate to display the newly created Sprite at. The value is in relation to the Group.x point.
* @param {number} y - The y coordinate to display the newly created Sprite at. The value is in relation to the Group.y point.
* @param {string} key - The Game.cache key of the image that this Sprite will use.
* @param {number|string} [frame] - If the Sprite image contains multiple frames you can specify which one to use here.
* @param {boolean} [exists=true] - The default exists state of the Sprite.
* @return {Phaser.Sprite} The child that was created.
*/
Phaser.Group.prototype.create = function (x, y, key, frame, exists) {
2014-02-05 06:29:17 +00:00
if (typeof exists === 'undefined') { exists = true; }
2013-11-01 18:16:52 +00:00
var child = new Phaser.Sprite(this.game, x, y, key, frame);
2013-10-02 00:16:40 +00:00
child.exists = exists;
child.visible = exists;
child.alive = exists;
2013-10-02 00:16:40 +00:00
this.addChild(child);
if (child.events)
{
child.events.onAddedToGroup.dispatch(child, this);
}
2013-10-02 00:16:40 +00:00
if (this.cursor === null)
{
this.cursor = child;
}
2013-10-02 00:16:40 +00:00
return child;
2013-10-02 00:16:40 +00:00
}
2013-10-02 00:16:40 +00:00
/**
* Automatically creates multiple Phaser.Sprite objects and adds them to the top of this Group.
* 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)
*
* @method Phaser.Group#createMultiple
* @param {number} quantity - The number of Sprites to create.
* @param {string} key - The Game.cache key of the image that this Sprite will use.
* @param {number|string} [frame] - If the Sprite image contains multiple frames you can specify which one to use here.
* @param {boolean} [exists=false] - The default exists state of the Sprite.
*/
Phaser.Group.prototype.createMultiple = function (quantity, key, frame, exists) {
2013-10-02 00:16:40 +00:00
if (typeof exists === 'undefined') { exists = false; }
2013-10-02 00:16:40 +00:00
for (var i = 0; i &lt; quantity; i++)
{
this.create(0, 0, key, frame, exists);
}
2013-10-02 00:16:40 +00:00
}
2013-10-02 00:16:40 +00:00
/**
* Advances the Group cursor to the next object in the Group. If it's at the end of the Group it wraps around to the first object.
*
* @method Phaser.Group#next
*/
Phaser.Group.prototype.next = function () {
2014-02-05 06:29:17 +00:00
if (this.cursor)
{
// Wrap the cursor?
if (this._cursorIndex === this.children.length)
2013-11-28 15:57:09 +00:00
{
this._cursorIndex = 0;
2013-11-28 15:57:09 +00:00
}
else
2013-11-28 15:57:09 +00:00
{
this._cursorIndex++;
2013-11-28 15:57:09 +00:00
}
2013-11-01 18:16:52 +00:00
this.cursor = this.children[this._cursorIndex];
}
2013-10-02 00:16:40 +00:00
}
/**
* Moves the Group cursor to the previous object in the Group. If it's at the start of the Group it wraps around to the last object.
*
* @method Phaser.Group#previous
*/
Phaser.Group.prototype.previous = function () {
if (this.cursor)
{
// Wrap the cursor?
if (this._cursorIndex === 0)
{
this._cursorIndex = this.children.length - 1;
}
else
2013-11-28 15:57:09 +00:00
{
this._cursorIndex--;
}
this.cursor = this.children[this._cursorIndex];
}
}
/**
* Swaps the position of two children in this Group. Both children must be in this Group.
* You cannot swap a child with itself, or swap un-parented children, doing so will return false.
*
* @method Phaser.Group#swap
* @param {*} child1 - The first child to swap.
* @param {*} child2 - The second child to swap.
*/
Phaser.Group.prototype.swap = function (child1, child2) {
2014-02-05 06:29:17 +00:00
return this.swapChildren(child1, child2);
}
2014-02-05 06:29:17 +00:00
/**
* Brings the given child to the top of this Group so it renders above all other children.
*
* @method Phaser.Group#bringToTop
* @param {*} child - The child to bring to the top of this Group.
* @return {*} The child that was moved.
*/
Phaser.Group.prototype.bringToTop = function (child) {
if (child.parent === this)
{
this.remove(child);
this.add(child);
}
2013-11-01 18:16:52 +00:00
return child;
2013-11-01 18:16:52 +00:00
}
2013-11-01 18:16:52 +00:00
/**
* Get the index position of the given child in this Group.
*
* @method Phaser.Group#getIndex
* @param {*} child - The child to get the index for.
* @return {number} The index of the child or -1 if it's not a member of this Group.
*/
Phaser.Group.prototype.getIndex = function (child) {
2013-11-28 15:57:09 +00:00
return this.children.indexOf(child);
2013-11-28 15:57:09 +00:00
}
2013-11-01 18:16:52 +00:00
/**
* Replaces a child of this Group with the given newChild. The newChild cannot be a member of this Group.
*
* @method Phaser.Group#replace
* @param {*} oldChild - The child in this Group that will be replaced.
* @param {*} newChild - The child to be inserted into this group.
*/
Phaser.Group.prototype.replace = function (oldChild, newChild) {
2013-11-28 15:57:09 +00:00
var index = this.getIndex(oldChild);
if (index !== -1)
{
if (newChild.parent !== undefined)
2013-11-28 15:57:09 +00:00
{
newChild.events.onRemovedFromGroup.dispatch(newChild, this);
newChild.parent.removeChild(newChild);
2013-11-28 15:57:09 +00:00
}
this.removeChild(oldChild);
this.addChildAt(newChild, index);
newChild.events.onAddedToGroup.dispatch(newChild, this);
if (this.cursor === oldChild)
2013-11-28 15:57:09 +00:00
{
this.cursor = newChild;
2013-11-28 15:57:09 +00:00
}
}
}
/**
* Sets the given property to the given value on the child. The operation controls the assignment of the value.
*
* @method Phaser.Group#setProperty
* @param {*} child - The child to set the property value on.
* @param {array} key - An array of strings that make up the property that will be set.
* @param {*} value - The value that will be set.
* @param {number} [operation=0] - Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it.
*/
Phaser.Group.prototype.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
var len = key.length;
if (len == 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 (len == 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 (len == 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 (len == 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; }
}
}
2013-11-28 15:57:09 +00:00
/**
* This function allows you to quickly set a property on a single child of this Group to a new value.
* The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication.
*
* @method Phaser.Group#set
* @param {Phaser.Sprite} child - The child to set the property on.
* @param {string} key - The property, as a string, to be set. For example: 'body.velocity.x'
* @param {*} value - The value that will be set.
* @param {boolean} [checkAlive=false] - If set then the child will only be updated if alive=true.
* @param {boolean} [checkVisible=false] - If set then the child will only be updated if visible=true.
* @param {number} [operation=0] - Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it.
*/
Phaser.Group.prototype.set = function (child, key, value, checkAlive, checkVisible, operation) {
2013-11-28 15:57:09 +00:00
key = key.split('.');
2013-11-28 15:57:09 +00:00
if (typeof checkAlive === 'undefined') { checkAlive = false; }
if (typeof checkVisible === 'undefined') { checkVisible = false; }
2013-11-28 15:57:09 +00:00
if ((checkAlive === false || (checkAlive && child.alive)) && (checkVisible === false || (checkVisible && child.visible)))
{
this.setProperty(child, key, value, operation);
}
2013-11-28 15:57:09 +00:00
}
2013-11-28 15:57:09 +00:00
/**
* This function allows you to quickly set the same property across all children of this Group to a new value.
* The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication.
*
* @method Phaser.Group#setAll
* @param {string} key - The property, as a string, to be set. For example: 'body.velocity.x'
* @param {*} value - The value that will be set.
* @param {boolean} [checkAlive=false] - If set then only children with alive=true will be updated.
* @param {boolean} [checkVisible=false] - If set then only children with visible=true will be updated.
* @param {number} [operation=0] - Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it.
*/
Phaser.Group.prototype.setAll = function (key, value, checkAlive, checkVisible, operation) {
2013-11-28 15:57:09 +00:00
key = key.split('.');
2013-11-28 15:57:09 +00:00
if (typeof checkAlive === 'undefined') { checkAlive = false; }
if (typeof checkVisible === 'undefined') { checkVisible = false; }
2013-11-28 15:57:09 +00:00
operation = operation || 0;
2013-11-28 15:57:09 +00:00
for (var i = 0, len = this.children.length; i &lt; len; i++)
{
if ((!checkAlive || (checkAlive && this.children[i].alive)) && (!checkVisible || (checkVisible && this.children[i].visible)))
2013-11-28 15:57:09 +00:00
{
this.setProperty(this.children[i], key, value, operation);
}
}
2013-11-28 15:57:09 +00:00
}
2013-11-28 15:57:09 +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 Phaser.Group#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.
*/
Phaser.Group.prototype.addAll = function (property, amount, checkAlive, checkVisible) {
2013-11-28 15:57:09 +00:00
this.setAll(property, amount, checkAlive, checkVisible, 1);
2013-11-28 15:57:09 +00:00
}
2013-11-28 15:57:09 +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 Phaser.Group#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.
*/
Phaser.Group.prototype.subAll = function (property, amount, checkAlive, checkVisible) {
2013-11-28 15:57:09 +00:00
this.setAll(property, amount, checkAlive, checkVisible, 2);
2013-11-28 15:57:09 +00:00
}
2013-10-02 00:16:40 +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 Phaser.Group#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.
*/
Phaser.Group.prototype.multiplyAll = function (property, amount, checkAlive, checkVisible) {
2013-10-02 00:16:40 +00:00
this.setAll(property, amount, checkAlive, checkVisible, 3);
2013-10-02 00:16:40 +00:00
}
2013-10-02 00:16:40 +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 Phaser.Group#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.
*/
Phaser.Group.prototype.divideAll = function (property, amount, checkAlive, checkVisible) {
2013-10-02 00:16:40 +00:00
this.setAll(property, amount, checkAlive, checkVisible, 4);
2013-10-02 00:16:40 +00:00
}
2013-10-02 00:16:40 +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 Phaser.Group#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.
*/
Phaser.Group.prototype.callAllExists = function (callback, existsValue) {
2013-10-02 00:16:40 +00:00
var args = Array.prototype.splice.call(arguments, 2);
2013-11-28 15:57:09 +00:00
for (var i = 0, len = this.children.length; i &lt; len; i++)
{
if (this.children[i].exists === existsValue && this.children[i][callback])
2013-11-28 15:57:09 +00:00
{
this.children[i][callback].apply(this.children[i], args);
2013-11-28 15:57:09 +00:00
}
}
2013-10-02 00:16:40 +00:00
}
2013-11-28 15:57:09 +00:00
/**
* Returns a reference to a function that exists on a child of the Group based on the given callback array.
*
* @method Phaser.Group#callbackFromArray
* @param {object} child - The object to inspect.
* @param {array} callback - The array of function names.
* @param {number} length - The size of the array (pre-calculated in callAll).
* @protected
*/
Phaser.Group.prototype.callbackFromArray = function (child, callback, length) {
2013-11-28 15:57:09 +00:00
// Kinda looks like a Christmas tree
2013-11-28 15:57:09 +00:00
if (length == 1)
{
if (child[callback[0]])
2013-11-28 15:57:09 +00:00
{
return child[callback[0]];
2013-11-28 15:57:09 +00:00
}
}
else if (length == 2)
{
if (child[callback[0]][callback[1]])
2013-11-28 15:57:09 +00:00
{
return child[callback[0]][callback[1]];
2013-11-28 15:57:09 +00:00
}
}
else if (length == 3)
{
if (child[callback[0]][callback[1]][callback[2]])
2013-11-28 15:57:09 +00:00
{
return child[callback[0]][callback[1]][callback[2]];
2013-11-28 15:57:09 +00:00
}
}
else if (length == 4)
{
if (child[callback[0]][callback[1]][callback[2]][callback[3]])
2014-02-05 06:29:17 +00:00
{
return child[callback[0]][callback[1]][callback[2]][callback[3]];
2014-02-05 06:29:17 +00:00
}
}
else
{
if (child[callback])
2013-11-28 15:57:09 +00:00
{
return child[callback];
2013-11-28 15:57:09 +00:00
}
}
2013-11-28 15:57:09 +00:00
return false;
2013-11-28 15:57:09 +00:00
}
2013-11-28 15:57:09 +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)
* After the method parameter and context you can add as many extra parameters as you like, which will all be passed to the child.
*
* @method Phaser.Group#callAll
* @param {string} method - A string containing the name of the function that will be called. The function must exist on the child.
* @param {string} [context=null] - A string containing the context under which the method will be executed. Set to null to default to the child.
* @param {...*} parameter - Additional parameters that will be passed to the method.
*/
Phaser.Group.prototype.callAll = function (method, context) {
2013-11-28 15:57:09 +00:00
if (typeof method === 'undefined')
{
return;
}
2013-11-28 15:57:09 +00:00
// Extract the method into an array
method = method.split('.');
2013-10-02 00:16:40 +00:00
var methodLength = method.length;
2013-10-02 00:16:40 +00:00
if (typeof context === 'undefined')
{
context = null;
}
else
{
// Extract the context into an array
if (typeof context === 'string')
2013-11-28 15:57:09 +00:00
{
context = context.split('.');
var contextLength = context.length;
2013-11-28 15:57:09 +00:00
}
}
2013-10-02 00:16:40 +00:00
var args = Array.prototype.splice.call(arguments, 2);
var callback = null;
var callbackContext = null;
2013-11-28 15:57:09 +00:00
for (var i = 0, len = this.children.length; i &lt; len; i++)
{
callback = this.callbackFromArray(this.children[i], method, methodLength);
2013-11-28 15:57:09 +00:00
if (context && callback)
2013-11-28 15:57:09 +00:00
{
callbackContext = this.callbackFromArray(this.children[i], context, contextLength);
if (callback)
2013-11-28 15:57:09 +00:00
{
callback.apply(callbackContext, args);
2013-11-28 15:57:09 +00:00
}
}
else if (callback)
2013-11-28 15:57:09 +00:00
{
callback.apply(this.children[i], args);
2013-11-28 15:57:09 +00:00
}
}
2013-11-28 15:57:09 +00:00
}
2013-11-28 15:57:09 +00:00
/**
* Allows you to call your own function on each member of this Group. You must pass the callback and context in which it will run.
* 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.
* For example: Group.forEach(awardBonusGold, this, true, 100, 500)
* Note: Currently this will skip any children which are Groups themselves.
*
* @method Phaser.Group#forEach
* @param {function} callback - The function that will be called. Each child of the Group will be passed to it as its first parameter.
* @param {Object} callbackContext - The context in which the function should be called (usually 'this').
* @param {boolean} checkExists - If set only children with exists=true will be passed to the callback, otherwise all children will be passed.
*/
Phaser.Group.prototype.forEach = function (callback, callbackContext, checkExists) {
2013-11-28 15:57:09 +00:00
if (typeof checkExists === 'undefined')
{
checkExists = false;
}
2013-11-28 15:57:09 +00:00
var args = Array.prototype.splice.call(arguments, 3);
args.unshift(null);
2013-11-28 15:57:09 +00:00
for (var i = 0, len = this.children.length; i &lt; len; i++)
{
if (!checkExists || (checkExists && this.children[i].exists))
2013-11-28 15:57:09 +00:00
{
args[0] = this.children[i];
callback.apply(callbackContext, args);
2013-11-28 15:57:09 +00:00
}
}
2013-11-28 15:57:09 +00:00
}
2013-11-01 18:16:52 +00:00
/**
* Allows you to call your own function on each alive member of this Group (where child.alive=true). You must pass the callback and context in which it will run.
* You can add as many parameters as you like, which will all be passed to the callback along with the child.
* For example: Group.forEachAlive(causeDamage, this, 500)
*
* @method Phaser.Group#forEachAlive
* @param {function} callback - The function that will be called. Each child of the Group will be passed to it as its first parameter.
* @param {Object} callbackContext - The context in which the function should be called (usually 'this').
*/
Phaser.Group.prototype.forEachExists = function (callback, callbackContext) {
2013-11-28 15:57:09 +00:00
var args = Array.prototype.splice.call(arguments, 2);
args.unshift(null);
2013-11-28 15:57:09 +00:00
this.iterate('exists', true, Phaser.Group.RETURN_TOTAL, callback, callbackContext, args);
2013-11-28 15:57:09 +00:00
}
2013-11-28 15:57:09 +00:00
/**
* Allows you to call your own function on each alive member of this Group (where child.alive=true). You must pass the callback and context in which it will run.
* You can add as many parameters as you like, which will all be passed to the callback along with the child.
* For example: Group.forEachAlive(causeDamage, this, 500)
*
* @method Phaser.Group#forEachAlive
* @param {function} callback - The function that will be called. Each child of the Group will be passed to it as its first parameter.
* @param {Object} callbackContext - The context in which the function should be called (usually 'this').
*/
Phaser.Group.prototype.forEachAlive = function (callback, callbackContext) {
2013-11-28 15:57:09 +00:00
var args = Array.prototype.splice.call(arguments, 2);
args.unshift(null);
2013-11-28 15:57:09 +00:00
this.iterate('alive', true, Phaser.Group.RETURN_TOTAL, callback, callbackContext, args);
2013-10-02 00:16:40 +00:00
}
2013-10-02 00:16:40 +00:00
/**
* Allows you to call your own function on each dead member of this Group (where alive=false). You must pass the callback and context in which it will run.
* You can add as many parameters as you like, which will all be passed to the callback along with the child.
* For example: Group.forEachDead(bringToLife, this)
*
* @method Phaser.Group#forEachDead
* @param {function} callback - The function that will be called. Each child of the Group will be passed to it as its first parameter.
* @param {Object} callbackContext - The context in which the function should be called (usually 'this').
*/
Phaser.Group.prototype.forEachDead = function (callback, callbackContext) {
2013-10-02 00:16:40 +00:00
var args = Array.prototype.splice.call(arguments, 2);
args.unshift(null);
2013-10-02 00:16:40 +00:00
this.iterate('alive', false, Phaser.Group.RETURN_TOTAL, callback, callbackContext, args);
2013-10-02 00:16:40 +00:00
}
2013-10-02 00:16:40 +00:00
/**
* Call this function to sort the group according to a particular value and order.
* For example to depth sort Sprites for Zelda-style game you might call `group.sort('y', Phaser.Group.SORT_ASCENDING)` at the bottom of your `State.update()`.
*
* @method Phaser.Group#sort
* @param {string} [index='y'] - The `string` name of the property you want to sort on.
* @param {number} [order=Phaser.Group.SORT_ASCENDING] - The `Group` constant that defines the sort order. Possible values are Phaser.Group.SORT_ASCENDING and Phaser.Group.SORT_DESCENDING.
*/
Phaser.Group.prototype.sort = function (index, order) {
if (typeof index === 'undefined') { index = 'y'; }
if (typeof order === 'undefined') { order = Phaser.Group.SORT_ASCENDING; }
2013-10-02 00:16:40 +00:00
}
2013-10-02 00:16:40 +00:00
Phaser.Group.prototype.sortHandler = function (a, b) {
}
/**
* Iterates over the children of the Group. When a child has a property matching key that equals the given value, it is considered as a match.
* Matched children can be sent to the optional callback, or simply returned or counted.
* You can add as many callback parameters as you like, which will all be passed to the callback along with the child, after the callbackContext parameter.
*
* @method Phaser.Group#iterate
* @param {string} key - The child property to check, i.e. 'exists', 'alive', 'health'
* @param {any} value - If child.key === this value it will be considered a match. Note that a strict comparison is used.
* @param {number} returnType - How to return the data from this method. Either Phaser.Group.RETURN_NONE, Phaser.Group.RETURN_TOTAL or Phaser.Group.RETURN_CHILD.
* @param {function} [callback=null] - Optional function that will be called on each matching child. Each child of the Group will be passed to it as its first parameter.
* @param {Object} [callbackContext] - The context in which the function should be called (usually 'this').
* @return {any} Returns either a numeric total (if RETURN_TOTAL was specified) or the child object.
*/
Phaser.Group.prototype.iterate = function (key, value, returnType, callback, callbackContext, args) {
2013-11-28 15:57:09 +00:00
if (returnType === Phaser.Group.RETURN_TOTAL && this.children.length === 0)
{
return 0;
}
2013-11-28 15:57:09 +00:00
if (typeof callback === 'undefined')
{
callback = false;
}
2013-11-28 15:57:09 +00:00
var total = 0;
2013-11-28 15:57:09 +00:00
for (var i = 0, len = this.children.length; i &lt; len; i++)
{
if (this.children[i][key] === value)
{
total++;
2013-11-28 15:57:09 +00:00
if (callback)
2013-11-28 15:57:09 +00:00
{
args[0] = this.children[i];
callback.apply(callbackContext, args);
2013-11-28 15:57:09 +00:00
}
if (returnType === Phaser.Group.RETURN_CHILD)
2013-11-28 15:57:09 +00:00
{
return this.children[i];
2013-11-28 15:57:09 +00:00
}
}
}
2013-11-28 15:57:09 +00:00
if (returnType === Phaser.Group.RETURN_TOTAL)
{
return total;
}
else if (returnType === Phaser.Group.RETURN_CHILD)
{
return null;
}
2013-11-28 15:57:09 +00:00
}
2013-11-28 15:57:09 +00:00
/**
* Call this function to retrieve the first object with exists == (the given state) in the Group.
*
* @method Phaser.Group#getFirstExists
* @param {boolean} state - True or false.
* @return {Any} The first child, or null if none found.
*/
Phaser.Group.prototype.getFirstExists = function (state) {
2013-10-02 00:16:40 +00:00
if (typeof state !== 'boolean')
{
state = true;
}
2013-10-02 00:16:40 +00:00
return this.iterate('exists', state, Phaser.Group.RETURN_CHILD);
2013-10-02 00:16:40 +00:00
}
2013-10-02 00:16:40 +00:00
/**
* Call this function to retrieve the first object with alive === true in the group.
* This is handy for checking if everything has been wiped out, or choosing a squad leader, etc.
*
* @method Phaser.Group#getFirstAlive
* @return {Any} The first alive child, or null if none found.
*/
Phaser.Group.prototype.getFirstAlive = function () {
2013-10-02 00:16:40 +00:00
return this.iterate('alive', true, Phaser.Group.RETURN_CHILD);
2013-10-02 00:16:40 +00:00
}
2013-10-02 00:16:40 +00:00
/**
* Call this function to retrieve the first object with alive === false in the group.
* This is handy for checking if everything has been wiped out, or choosing a squad leader, etc.
*
* @method Phaser.Group#getFirstDead
* @return {Any} The first dead child, or null if none found.
*/
Phaser.Group.prototype.getFirstDead = function () {
2013-10-02 00:16:40 +00:00
return this.iterate('alive', false, Phaser.Group.RETURN_CHILD);
2013-10-02 00:16:40 +00:00
}
2013-10-02 00:16:40 +00:00
/**
* Call this function to find out how many members of the group are alive.
*
* @method Phaser.Group#countLiving
* @return {number} The number of children flagged as alive.
*/
Phaser.Group.prototype.countLiving = function () {
2013-10-02 00:16:40 +00:00
return this.iterate('alive', true, Phaser.Group.RETURN_TOTAL);
2013-10-02 00:16:40 +00:00
}
2013-10-02 00:16:40 +00:00
/**
* Call this function to find out how many members of the group are dead.
*
* @method Phaser.Group#countDead
* @return {number} The number of children flagged as dead.
*/
Phaser.Group.prototype.countDead = function () {
2013-10-02 00:16:40 +00:00
return this.iterate('alive', false, Phaser.Group.RETURN_TOTAL);
2013-10-02 00:16:40 +00:00
}
2013-10-02 00:16:40 +00:00
/**
* Returns a member at random from the group.
*
* @method Phaser.Group#getRandom
* @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.
* @return {Any} A random child of this Group.
*/
Phaser.Group.prototype.getRandom = function (startIndex, length) {
2013-10-02 00:16:40 +00:00
if (this.children.length === 0)
{
return null;
}
2013-10-02 00:16:40 +00:00
startIndex = startIndex || 0;
length = length || this.children.length;
2013-10-02 00:16:40 +00:00
return this.game.math.getRandom(this.children, startIndex, length);
2013-10-02 00:16:40 +00:00
}
2013-11-28 15:57:09 +00:00
/**
* Removes the given child from this Group and sets its group property to null.
*
* @method Phaser.Group#remove
* @param {Any} child - The child to remove.
* @return {boolean} true if the child was removed from this Group, otherwise false.
*/
Phaser.Group.prototype.remove = function (child) {
2013-11-28 15:57:09 +00:00
if (this.children.length === 0)
{
return;
}
2013-11-28 15:57:09 +00:00
if (child.events)
{
child.events.onRemovedFromGroup.dispatch(child, this);
}
2013-11-28 15:57:09 +00:00
this.removeChild(child);
2013-11-28 15:57:09 +00:00
if (this.cursor === child)
{
this.next();
}
2013-11-28 15:57:09 +00:00
return true;
2013-11-28 15:57:09 +00:00
}
2013-11-28 15:57:09 +00:00
/**
* Removes all children from this Group, setting all group properties to null.
* The Group container remains on the display list.
*
* @method Phaser.Group#removeAll
*/
Phaser.Group.prototype.removeAll = function () {
2013-11-28 15:57:09 +00:00
if (this.children.length === 0)
{
return;
}
2013-11-28 15:57:09 +00:00
do
{
if (this.children[0].events)
2013-11-28 15:57:09 +00:00
{
this.children[0].events.onRemovedFromGroup.dispatch(this.children[0], this);
2013-11-28 15:57:09 +00:00
}
this.removeChild(this.children[0]);
}
while (this.children.length > 0);
2013-11-28 15:57:09 +00:00
this.cursor = null;
2013-11-28 15:57:09 +00:00
}
2013-11-28 15:57:09 +00:00
/**
* Removes all children from this Group whos index falls beteen the given startIndex and endIndex values.
*
* @method Phaser.Group#removeBetween
* @param {number} startIndex - The index to start removing children from.
* @param {number} endIndex - The index to stop removing children from. Must be higher than startIndex and less than the length of the Group.
*/
Phaser.Group.prototype.removeBetween = function (startIndex, endIndex) {
2013-11-28 15:57:09 +00:00
if (this.children.length === 0)
{
return;
}
2013-11-28 15:57:09 +00:00
if (startIndex > endIndex || startIndex &lt; 0 || endIndex > this.children.length)
{
return false;
}
2013-11-28 15:57:09 +00:00
for (var i = startIndex; i &lt; endIndex; i++)
{
if (this.children[i].events)
2013-11-28 15:57:09 +00:00
{
this.children[i].events.onRemovedFromGroup.dispatch(this.children[i], this);
2013-11-28 15:57:09 +00:00
}
this.removeChild(this.children[i]);
2013-11-28 15:57:09 +00:00
if (this.cursor === child)
2014-02-05 06:29:17 +00:00
{
this.cursor = null;
2014-02-05 06:29:17 +00:00
}
}
2013-11-28 15:57:09 +00:00
}
2013-11-28 15:57:09 +00:00
/**
* Destroys this Group. Removes all children, then removes the container from the display list and nulls references.
*
* @method Phaser.Group#destroy
* @param {boolean} [destroyChildren=false] - Should every child of this Group have its destroy method called?
*/
Phaser.Group.prototype.destroy = function (destroyChildren) {
2013-11-28 15:57:09 +00:00
if (typeof destroyChildren === 'undefined') { destroyChildren = false; }
2013-11-28 15:57:09 +00:00
if (destroyChildren)
{
if (this.children.length > 0)
2013-11-28 15:57:09 +00:00
{
do
2013-11-28 15:57:09 +00:00
{
if (this.children[0].group)
2013-11-28 15:57:09 +00:00
{
this.children[0].destroy();
2013-11-28 15:57:09 +00:00
}
}
while (this.children.length > 0);
2013-11-28 15:57:09 +00:00
}
}
else
{
this.removeAll();
}
2013-11-28 15:57:09 +00:00
this.parent.removeChild(this);
2013-11-28 15:57:09 +00:00
this.game = null;
2013-10-02 00:16:40 +00:00
this.exists = false;
2013-10-02 00:16:40 +00:00
this.cursor = null;
}
2014-02-05 06:29:17 +00:00
/**
* @name Phaser.Group#total
2014-02-05 06:29:17 +00:00
* @property {number} total - The total number of children in this Group who have a state of exists = true.
* @readonly
*/
Object.defineProperty(Phaser.Group.prototype, "total", {
get: function () {
2014-02-05 06:29:17 +00:00
return this.iterate('exists', true, Phaser.Group.RETURN_TOTAL);
2014-02-05 06:29:17 +00:00
}
});
2013-10-02 00:16:40 +00:00
/**
* @name Phaser.Group#length
2014-02-05 06:29:17 +00:00
* @property {number} length - The total number of children in this Group, regardless of their exists/alive status.
2013-10-02 11:11:22 +00:00
* @readonly
2013-10-02 00:16:40 +00:00
*/
Object.defineProperty(Phaser.Group.prototype, "length", {
get: function () {
2014-02-05 06:29:17 +00:00
return this.children.length;
2014-02-05 06:29:17 +00:00
2013-10-02 00:16:40 +00:00
}
});
/**
* The angle of rotation of the Group container. This will adjust the Group container itself by modifying its rotation.
* This will have no impact on the rotation value of its children, but it will update their worldTransform and on-screen position.
* @name Phaser.Group#angle
* @property {number} angle - The angle of rotation given in degrees, where 0 degrees = to the right.
*/
Object.defineProperty(Phaser.Group.prototype, "angle", {
get: function() {
return Phaser.Math.radToDeg(this.rotation);
2013-10-02 00:16:40 +00:00
},
set: function(value) {
this.rotation = Phaser.Math.degToRad(value);
2013-10-02 00:16:40 +00:00
}
});
// Documentation stubs
/**
* The x coordinate of the Group container. You can adjust the Group container itself by modifying its coordinates.
* This will have no impact on the x/y coordinates of its children, but it will update their worldTransform and on-screen position.
* @name Phaser.Group#x
* @property {number} x - The x coordinate of the Group container.
*/
/**
* The y coordinate of the Group container. You can adjust the Group container itself by modifying its coordinates.
* This will have no impact on the x/y coordinates of its children, but it will update their worldTransform and on-screen position.
* @name Phaser.Group#y
* @property {number} y - The y coordinate of the Group container.
*/
2013-10-02 00:16:40 +00:00
/**
* The angle of rotation of the Group container. This will adjust the Group container itself by modifying its rotation.
* This will have no impact on the rotation value of its children, but it will update their worldTransform and on-screen position.
* @name Phaser.Group#rotation
* @property {number} rotation - The angle of rotation given in radians.
*/
/**
* @name Phaser.Group#visible
* @property {boolean} visible - The visible state of the Group. Non-visible Groups and all of their children are not rendered.
*/
/**
* @name Phaser.Group#alpha
* @property {number} alpha - The alpha value of the Group container.
*/
2013-10-02 00:16:40 +00:00
</pre>
</article>
</section>
</div>
<div class="clearfix"></div>
<footer>
<span class="copyright">
2014-02-05 06:29:17 +00:00
Phaser Copyright © 2012-2014 Photon Storm Ltd.
2013-10-02 00:16:40 +00:00
</span>
<br />
<span class="jsdoc-message">
2013-10-25 15:54:40 +00:00
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-dev</a>
on Sat Feb 08 2014 07:19:40 GMT-0000 (GMT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
2013-10-02 00:16:40 +00:00
</span>
</footer>
</div>
<br clear="both">
</div>
</div>
<script src="scripts/sunlight.js"></script>
<script src="scripts/sunlight.javascript.js"></script>
<script src="scripts/sunlight-plugin.doclinks.js"></script>
<script src="scripts/sunlight-plugin.linenumbers.js"></script>
<script src="scripts/sunlight-plugin.menu.js"></script>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/jquery.scrollTo.js"></script>
<script src="scripts/jquery.localScroll.js"></script>
<script src="scripts/bootstrap-dropdown.js"></script>
<script src="scripts/toc.js"></script>
<script> Sunlight.highlightAll({lineNumbers:true, showMenu: true, enableDoclinks :true}); </script>
<script>
$( function () {
$( "#toc" ).toc( {
selectors : "h1,h2,h3,h4",
showAndHide : false,
scrollTo : 60
} );
$( "#toc>ul" ).addClass( "nav nav-pills nav-stacked" );
$( "#main span[id^='toc']" ).addClass( "toc-shim" );
} );
</script>
</body>
</html>