2018-02-12 16:01:20 +00:00
|
|
|
|
/**
|
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
|
*/
|
|
|
|
|
|
2017-11-02 17:04:02 +00:00
|
|
|
|
var Actions = require('../../actions/');
|
2017-03-22 23:16:44 +00:00
|
|
|
|
var Class = require('../../utils/Class');
|
2017-11-13 23:32:14 +00:00
|
|
|
|
var GetFastValue = require('../../utils/object/GetFastValue');
|
2017-04-26 15:03:14 +00:00
|
|
|
|
var GetValue = require('../../utils/object/GetValue');
|
2017-03-28 22:38:08 +00:00
|
|
|
|
var Range = require('../../utils/array/Range');
|
2017-11-02 17:04:02 +00:00
|
|
|
|
var Set = require('../../structs/Set');
|
2017-03-28 02:09:59 +00:00
|
|
|
|
var Sprite = require('../sprite/Sprite');
|
2017-03-22 23:16:44 +00:00
|
|
|
|
|
2018-03-21 11:19:31 +00:00
|
|
|
|
/**
|
|
|
|
|
* @callback GroupCallback
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {Phaser.GameObjects.GameObject} item - A group member
|
2018-03-21 11:19:31 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @callback GroupMultipleCreateCallback
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {Phaser.GameObjects.GameObject[]} items - The newly created group members
|
2018-03-21 11:19:31 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @typedef {object} GroupConfig
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @property {?object} [classType=Sprite] - Sets {@link Phaser.GameObjects.Group#classType}.
|
|
|
|
|
* @property {?boolean} [active=true] - Sets {@link Phaser.GameObjects.Group#active}.
|
|
|
|
|
* @property {?number} [maxSize=-1] - Sets {@link Phaser.GameObjects.Group#maxSize}.
|
|
|
|
|
* @property {?string} [defaultKey=null] - Sets {@link Phaser.GameObjects.Group#defaultKey}.
|
|
|
|
|
* @property {?(string|integer)} [defaultFrame=null] - Sets {@link Phaser.GameObjects.Group#defaultFrame}.
|
|
|
|
|
* @property {?boolean} [runChildUpdate=false] - Sets {@link Phaser.GameObjects.Group#runChildUpdate}.
|
|
|
|
|
* @property {?GroupCallback} [createCallback=null] - Sets {@link Phaser.GameObjects.Group#createCallback}.
|
|
|
|
|
* @property {?GroupCallback} [removeCallback=null] - Sets {@link Phaser.GameObjects.Group#removeCallback}.
|
|
|
|
|
* @property {?GroupMultipleCreateCallback} [createMultipleCallback=null] - Sets {@link Phaser.GameObjects.Group#createMultipleCallback}.
|
2018-03-21 11:19:31 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @typedef {object} GroupCreateConfig
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* The total number of objects created will be
|
|
|
|
|
*
|
|
|
|
|
* key.length * frame.length * frameQuantity * (yoyo ? 2 : 1) * (1 + repeat)
|
|
|
|
|
*
|
|
|
|
|
* In the simplest case, 1 + `repeat` objects will be created.
|
|
|
|
|
*
|
|
|
|
|
* If `max` is positive, then the total created will not exceed `max`.
|
|
|
|
|
*
|
|
|
|
|
* `key` is required.
|
|
|
|
|
*
|
|
|
|
|
* @property {?object} [classType] - The class of each new Game Object.
|
|
|
|
|
* @property {string} [key] - The texture key of each new Game Object.
|
|
|
|
|
* @property {?(string|integer)} [frame=null] - The texture frame of each new Game Object.
|
|
|
|
|
* @property {?boolean} [visible=true] - The visible state of each new Game Object.
|
|
|
|
|
* @property {?boolean} [active=true] - The active state of each new Game Object.
|
|
|
|
|
* @property {?number} [repeat=0] - The number of times each `key` × `frame` combination will be *repeated* (after the first combination).
|
|
|
|
|
* @property {?boolean} [randomKey=false] - Select a `key` at random.
|
|
|
|
|
* @property {?boolean} [randomFrame=false] - Select a `frame` at random.
|
|
|
|
|
* @property {?boolean} [yoyo=false] - Select keys and frames by moving forward then backward through `key` and `frame`.
|
|
|
|
|
* @property {?number} [frameQuantity=1] - The number of times each `frame` should be combined with one `key`.
|
|
|
|
|
* @property {?number} [max=0] - The maximum number of new Game Objects to create. 0 is no maximum.
|
|
|
|
|
* @property {?object} [setXY]
|
|
|
|
|
* @property {?number} [setXY.x=0] - The horizontal position of each new Game Object.
|
|
|
|
|
* @property {?number} [setXY.y=0] - The vertical position of each new Game Object.
|
|
|
|
|
* @property {?number} [setXY.stepX=0] - Increment each Game Object's horizontal position from the previous by this amount, starting from `setXY.x`.
|
|
|
|
|
* @property {?number} [setXY.stepY=0] - Increment each Game Object's vertical position from the previous by this amount, starting from `setXY.y`.
|
|
|
|
|
* @property {?object} [setRotation]
|
|
|
|
|
* @property {?number} [setRotation.value=0] - Rotation of each new Game Object.
|
|
|
|
|
* @property {?number} [setRotation.step=0] - Increment each Game Object's rotation from the previous by this amount, starting at `setRotation.value`.
|
|
|
|
|
* @property {?object} [setScale]
|
|
|
|
|
* @property {?number} [setScale.x=0] - The horizontal scale of each new Game Object.
|
|
|
|
|
* @property {?number} [setScale.y=0] - The vertical scale of each new Game Object.
|
|
|
|
|
* @property {?number} [setScale.stepX=0] - Increment each Game Object's horizontal scale from the previous by this amount, starting from `setScale.x`.
|
|
|
|
|
* @property {?number} [setScale.stepY=0] - Increment each Game object's vertical scale from the previous by this amount, starting from `setScale.y`.
|
|
|
|
|
* @property {?object} [setAlpha]
|
|
|
|
|
* @property {?number} [setAlpha.value=0] - The alpha value of each new Game Object.
|
|
|
|
|
* @property {?number} [setAlpha.step=0] - Increment each Game Object's alpha from the previous by this amount, starting from `setAlpha.value`.
|
|
|
|
|
* @property {?*} [hitArea] - A geometric shape that defines the hit area for the Game Object.
|
|
|
|
|
* @property {?HitAreaCallback} [hitAreaCallback] - A callback to be invoked when the Game Object is interacted with.
|
|
|
|
|
* @property {?(false|GridAlignConfig)} [gridAlign=false] - Align the new Game Objects in a grid using these settings.
|
|
|
|
|
*
|
|
|
|
|
* @see Phaser.Actions.GridAlign
|
|
|
|
|
* @see Phaser.Actions.SetAlpha
|
|
|
|
|
* @see Phaser.Actions.SetHitArea
|
|
|
|
|
* @see Phaser.Actions.SetRotation
|
|
|
|
|
* @see Phaser.Actions.SetScale
|
|
|
|
|
* @see Phaser.Actions.SetXY
|
|
|
|
|
* @see Phaser.GameObjects.Group#createFromConfig
|
|
|
|
|
* @see Phaser.Utils.Array.Range
|
2018-03-21 11:19:31 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @classdesc A Group is a way for you to create, manipulate, or recycle similar Game Objects.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Group membership is non-exclusive. A Game Object can belong to several groups, one group, or none.
|
|
|
|
|
*
|
|
|
|
|
* Groups themselves aren't displayable, and can't be positioned, rotated, scaled, or hidden.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @class Group
|
|
|
|
|
* @memberOf Phaser.GameObjects
|
|
|
|
|
* @constructor
|
|
|
|
|
* @since 3.0.0
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {Phaser.Scene} scene - The scene this group belongs to.
|
|
|
|
|
* @param {?(Phaser.GameObjects.GameObject[]|GroupConfig)} [children] - Game objects to add to this group; or the `config` argument.
|
|
|
|
|
* @param {GroupConfig} [config] - Settings for this group.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @see Phaser.Physics.Arcade.Group
|
|
|
|
|
* @see Phaser.Physics.Arcade.StaticGroup
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2017-06-26 20:08:08 +00:00
|
|
|
|
var Group = new Class({
|
2017-03-22 23:16:44 +00:00
|
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
|
function Group (scene, children, config)
|
2017-03-22 23:16:44 +00:00
|
|
|
|
{
|
2017-11-09 03:59:56 +00:00
|
|
|
|
if (config === undefined && !Array.isArray(children) && typeof children === 'object')
|
|
|
|
|
{
|
|
|
|
|
config = children;
|
|
|
|
|
children = null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* This scene this group belongs to.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @name Phaser.GameObjects.Group#scene
|
|
|
|
|
* @type {Phaser.Scene}
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*/
|
2017-07-14 13:30:20 +00:00
|
|
|
|
this.scene = scene;
|
2017-03-27 23:05:08 +00:00
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Members of this group.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @name Phaser.GameObjects.Group#children
|
2018-03-23 15:54:12 +00:00
|
|
|
|
* @type {Phaser.Structs.Set.<Phaser.GameObjects.GameObject>}
|
2018-02-12 17:21:06 +00:00
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*/
|
2017-03-27 15:59:51 +00:00
|
|
|
|
this.children = new Set(children);
|
2017-03-28 02:09:59 +00:00
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* A flag identifying this object as a group.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @name Phaser.GameObjects.Group#isParent
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
* @default true
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*/
|
2017-11-09 03:59:56 +00:00
|
|
|
|
this.isParent = true;
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* The class to create new group members from.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @name Phaser.GameObjects.Group#classType
|
|
|
|
|
* @type {object}
|
|
|
|
|
* @since 3.0.0
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @default Phaser.GameObjects.Sprite
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2017-11-13 23:32:14 +00:00
|
|
|
|
this.classType = GetFastValue(config, 'classType', Sprite);
|
2017-11-09 03:59:56 +00:00
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Whether this group runs its {@link Phaser.GameObjects.Group#preUpdate} method
|
|
|
|
|
* (which may update any members).
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @name Phaser.GameObjects.Group#active
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*/
|
2017-11-13 23:32:14 +00:00
|
|
|
|
this.active = GetFastValue(config, 'active', true);
|
2018-02-12 17:21:06 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* The maximum size of this group, if used as a pool. -1 is no limit.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @name Phaser.GameObjects.Group#maxSize
|
|
|
|
|
* @type {integer}
|
|
|
|
|
* @since 3.0.0
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @default -1
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2017-11-13 23:32:14 +00:00
|
|
|
|
this.maxSize = GetFastValue(config, 'maxSize', -1);
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* A default texture key to use when creating new group members.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @name Phaser.GameObjects.Group#defaultKey
|
|
|
|
|
* @type {string}
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*/
|
2017-11-13 23:32:14 +00:00
|
|
|
|
this.defaultKey = GetFastValue(config, 'defaultKey', null);
|
2018-02-12 17:21:06 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* A default texture frame to use when creating new group members.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @name Phaser.GameObjects.Group#defaultFrame
|
2018-03-20 14:56:31 +00:00
|
|
|
|
* @type {(string|integer)}
|
2018-02-12 17:21:06 +00:00
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*/
|
2017-11-13 23:32:14 +00:00
|
|
|
|
this.defaultFrame = GetFastValue(config, 'defaultFrame', null);
|
2018-02-12 17:21:06 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Whether to call the update method of any members.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @name Phaser.GameObjects.Group#runChildUpdate
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
* @default false
|
|
|
|
|
* @since 3.0.0
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @see Phaser.GameObjects.Group#preUpdate
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2017-11-13 23:32:14 +00:00
|
|
|
|
this.runChildUpdate = GetFastValue(config, 'runChildUpdate', false);
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* A function to be called when adding or creating group members.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @name Phaser.GameObjects.Group#createCallback
|
2018-03-21 11:19:31 +00:00
|
|
|
|
* @type {?GroupCallback}
|
2018-02-12 17:21:06 +00:00
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*/
|
2017-11-13 23:32:14 +00:00
|
|
|
|
this.createCallback = GetFastValue(config, 'createCallback', null);
|
2018-02-12 17:21:06 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* A function to be called when removing group members.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @name Phaser.GameObjects.Group#removeCallback
|
2018-03-21 11:19:31 +00:00
|
|
|
|
* @type {?GroupCallback}
|
2018-02-12 17:21:06 +00:00
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*/
|
2017-11-13 23:32:14 +00:00
|
|
|
|
this.removeCallback = GetFastValue(config, 'removeCallback', null);
|
2018-02-12 17:21:06 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* A function to be called when creating several group members at once.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @name Phaser.GameObjects.Group#createMultipleCallback
|
2018-03-21 11:19:31 +00:00
|
|
|
|
* @type {?GroupMultipleCreateCallback}
|
2018-02-12 17:21:06 +00:00
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*/
|
2017-12-02 04:03:22 +00:00
|
|
|
|
this.createMultipleCallback = GetFastValue(config, 'createMultipleCallback', null);
|
2017-06-30 15:58:42 +00:00
|
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
|
{
|
|
|
|
|
this.createMultiple(config);
|
|
|
|
|
}
|
2017-03-22 23:16:44 +00:00
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Creates a new Game Object and adds it to this group, unless the group {@link Phaser.GameObjects.Group#isFull is full}.
|
|
|
|
|
*
|
|
|
|
|
* Calls {@link Phaser.GameObjects.Group#createCallback}.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#create
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {number} [x=0] - The horizontal position of the new Game Object in the world.
|
|
|
|
|
* @param {number} [y=0] - The vertical position of the new Game Object in the world.
|
|
|
|
|
* @param {string} [key=defaultKey] - The texture key of the new Game Object.
|
|
|
|
|
* @param {(string|integer)} [frame=defaultFrame] - The texture frame of the new Game Object.
|
|
|
|
|
* @param {boolean} [visible=true] - The {@link Phaser.GameObjects.Components.Visible#visible} state of the new Game Object.
|
|
|
|
|
* @param {boolean} [active=true] - The {@link Phaser.GameObjects.GameObject#active} state of the new Game Object.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @return {Phaser.GameObjects.GameObject} The new Game Object.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2018-03-05 06:05:11 +00:00
|
|
|
|
create: function (x, y, key, frame, visible, active)
|
2017-06-27 15:21:40 +00:00
|
|
|
|
{
|
2018-03-28 13:11:46 +00:00
|
|
|
|
if (x === undefined) { x = 0; }
|
|
|
|
|
if (y === undefined) { y = 0; }
|
2017-11-13 23:32:14 +00:00
|
|
|
|
if (key === undefined) { key = this.defaultKey; }
|
|
|
|
|
if (frame === undefined) { frame = this.defaultFrame; }
|
|
|
|
|
if (visible === undefined) { visible = true; }
|
2018-03-05 06:05:11 +00:00
|
|
|
|
if (active === undefined) { active = true; }
|
2017-06-27 15:21:40 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
// Pool?
|
|
|
|
|
if (this.isFull())
|
2017-06-27 15:21:40 +00:00
|
|
|
|
{
|
2017-11-13 23:32:14 +00:00
|
|
|
|
return null;
|
2017-06-27 15:21:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
var child = new this.classType(this.scene, x, y, key, frame);
|
2017-03-22 23:16:44 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
this.scene.sys.displayList.add(child);
|
2017-03-23 00:07:41 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
if (child.preUpdate)
|
2017-11-09 03:59:56 +00:00
|
|
|
|
{
|
2017-11-13 23:32:14 +00:00
|
|
|
|
this.scene.sys.updateList.add(child);
|
2017-11-09 03:59:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
child.visible = visible;
|
2018-03-05 06:05:11 +00:00
|
|
|
|
child.setActive(active);
|
2017-03-22 23:16:44 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
this.add(child);
|
2017-03-23 00:07:41 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
return child;
|
2017-03-22 23:16:44 +00:00
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Creates several Game Objects and adds them to this group.
|
|
|
|
|
*
|
|
|
|
|
* Calls {@link Phaser.GameObjects.Group#createMultipleCallback}
|
|
|
|
|
* and {@link Phaser.GameObjects.Group#createCallback}.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#createMultiple
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {GroupCreateConfig|GroupCreateConfig[]} config - Creation settings. This can be a single configuration object or an array of such objects, which will be applied in turn.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @return {Phaser.GameObjects.GameObject[]} The newly created Game Objects.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2017-11-13 23:32:14 +00:00
|
|
|
|
createMultiple: function (config)
|
2017-03-28 02:09:59 +00:00
|
|
|
|
{
|
2017-11-13 23:32:14 +00:00
|
|
|
|
if (!Array.isArray(config))
|
2017-07-04 15:44:16 +00:00
|
|
|
|
{
|
2017-11-13 23:32:14 +00:00
|
|
|
|
config = [ config ];
|
2017-07-04 15:44:16 +00:00
|
|
|
|
}
|
2017-03-28 02:09:59 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
var output = [];
|
2017-03-28 02:09:59 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
for (var i = 0; i < config.length; i++)
|
|
|
|
|
{
|
|
|
|
|
var entries = this.createFromConfig(config[i]);
|
2017-03-28 23:09:16 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
output = output.concat(entries);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return output;
|
2017-03-28 02:09:59 +00:00
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* A helper for {@link Phaser.GameObjects.Group#createMultiple}.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#createFromConfig
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {GroupCreateConfig} options - Creation settings.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @return {Phaser.GameObjects.GameObject[]} The newly created Game Objects.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2017-03-29 00:12:14 +00:00
|
|
|
|
createFromConfig: function (options)
|
2017-03-28 02:09:59 +00:00
|
|
|
|
{
|
2017-11-13 23:32:14 +00:00
|
|
|
|
this.classType = GetFastValue(options, 'classType', this.classType);
|
2017-07-12 11:57:53 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
var key = GetFastValue(options, 'key', undefined);
|
|
|
|
|
var frame = GetFastValue(options, 'frame', null);
|
|
|
|
|
var visible = GetFastValue(options, 'visible', true);
|
2018-03-05 06:05:11 +00:00
|
|
|
|
var active = GetFastValue(options, 'active', true);
|
2017-03-28 02:09:59 +00:00
|
|
|
|
|
2017-03-29 00:12:14 +00:00
|
|
|
|
var entries = [];
|
|
|
|
|
|
|
|
|
|
// Can't do anything without at least a key
|
|
|
|
|
if (key === undefined)
|
2017-03-28 02:09:59 +00:00
|
|
|
|
{
|
2017-03-29 00:12:14 +00:00
|
|
|
|
return entries;
|
2017-03-28 02:09:59 +00:00
|
|
|
|
}
|
2017-03-29 00:12:14 +00:00
|
|
|
|
else
|
2017-03-28 02:09:59 +00:00
|
|
|
|
{
|
2017-03-29 00:12:14 +00:00
|
|
|
|
if (!Array.isArray(key))
|
|
|
|
|
{
|
|
|
|
|
key = [ key ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Array.isArray(frame))
|
|
|
|
|
{
|
|
|
|
|
frame = [ frame ];
|
|
|
|
|
}
|
2017-03-28 02:09:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-28 22:38:08 +00:00
|
|
|
|
// Build an array of key frame pairs to loop through
|
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
var repeat = GetFastValue(options, 'repeat', 0);
|
|
|
|
|
var randomKey = GetFastValue(options, 'randomKey', false);
|
|
|
|
|
var randomFrame = GetFastValue(options, 'randomFrame', false);
|
|
|
|
|
var yoyo = GetFastValue(options, 'yoyo', false);
|
|
|
|
|
var quantity = GetFastValue(options, 'frameQuantity', 1);
|
|
|
|
|
var max = GetFastValue(options, 'max', 0);
|
2017-03-28 22:38:08 +00:00
|
|
|
|
|
2017-11-09 03:59:56 +00:00
|
|
|
|
// If a grid is set we use that to override the quantity?
|
|
|
|
|
|
2017-03-28 22:38:08 +00:00
|
|
|
|
var range = Range(key, frame, {
|
|
|
|
|
max: max,
|
|
|
|
|
qty: quantity,
|
|
|
|
|
random: randomKey,
|
|
|
|
|
randomB: randomFrame,
|
|
|
|
|
repeat: repeat,
|
|
|
|
|
yoyo: yoyo
|
2017-03-28 02:09:59 +00:00
|
|
|
|
});
|
|
|
|
|
|
2017-03-29 00:12:14 +00:00
|
|
|
|
for (var c = 0; c < range.length; c++)
|
2017-03-28 22:38:08 +00:00
|
|
|
|
{
|
2018-03-05 06:05:11 +00:00
|
|
|
|
entries.push(this.create(0, 0, range[c].a, range[c].b, visible, active));
|
2017-03-28 22:38:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-28 23:09:16 +00:00
|
|
|
|
// Post-creation options (applied only to those items created in this call):
|
2017-03-28 13:01:35 +00:00
|
|
|
|
|
2017-04-26 15:03:14 +00:00
|
|
|
|
var x = GetValue(options, 'setXY.x', 0);
|
|
|
|
|
var y = GetValue(options, 'setXY.y', 0);
|
|
|
|
|
var stepX = GetValue(options, 'setXY.stepX', 0);
|
|
|
|
|
var stepY = GetValue(options, 'setXY.stepY', 0);
|
2017-03-28 13:01:35 +00:00
|
|
|
|
|
2017-03-28 23:09:16 +00:00
|
|
|
|
Actions.SetXY(entries, x, y, stepX, stepY);
|
2017-03-28 13:01:35 +00:00
|
|
|
|
|
2017-04-26 15:03:14 +00:00
|
|
|
|
var rotation = GetValue(options, 'setRotation.value', 0);
|
|
|
|
|
var stepRotation = GetValue(options, 'setRotation.step', 0);
|
2017-03-28 13:01:35 +00:00
|
|
|
|
|
2017-03-28 23:09:16 +00:00
|
|
|
|
Actions.SetRotation(entries, rotation, stepRotation);
|
2017-03-28 13:01:35 +00:00
|
|
|
|
|
2017-04-26 15:03:14 +00:00
|
|
|
|
var scaleX = GetValue(options, 'setScale.x', 1);
|
|
|
|
|
var scaleY = GetValue(options, 'setScale.y', scaleX);
|
|
|
|
|
var stepScaleX = GetValue(options, 'setScale.stepX', 0);
|
|
|
|
|
var stepScaleY = GetValue(options, 'setScale.stepY', 0);
|
2017-03-28 23:44:08 +00:00
|
|
|
|
|
|
|
|
|
Actions.SetScale(entries, scaleX, scaleY, stepScaleX, stepScaleY);
|
|
|
|
|
|
2017-04-26 15:03:14 +00:00
|
|
|
|
var alpha = GetValue(options, 'setAlpha.value', 1);
|
|
|
|
|
var stepAlpha = GetValue(options, 'setAlpha.step', 0);
|
2017-03-28 13:01:35 +00:00
|
|
|
|
|
2017-03-28 23:09:16 +00:00
|
|
|
|
Actions.SetAlpha(entries, alpha, stepAlpha);
|
2017-03-28 13:01:35 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
var hitArea = GetFastValue(options, 'hitArea', null);
|
|
|
|
|
var hitAreaCallback = GetFastValue(options, 'hitAreaCallback', null);
|
2017-07-13 01:35:29 +00:00
|
|
|
|
|
|
|
|
|
if (hitArea)
|
|
|
|
|
{
|
|
|
|
|
Actions.SetHitArea(entries, hitArea, hitAreaCallback);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
var grid = GetFastValue(options, 'gridAlign', false);
|
2017-07-12 11:28:21 +00:00
|
|
|
|
|
|
|
|
|
if (grid)
|
|
|
|
|
{
|
|
|
|
|
Actions.GridAlign(entries, grid);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-02 04:03:22 +00:00
|
|
|
|
if (this.createMultipleCallback)
|
|
|
|
|
{
|
|
|
|
|
this.createMultipleCallback.call(this, entries);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-28 02:09:59 +00:00
|
|
|
|
return entries;
|
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Updates any group members, if {@link Phaser.GameObjects.Group#runChildUpdate} is enabled.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#preUpdate
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {number} time - The current timestamp.
|
|
|
|
|
* @param {number} delta - The delta time elapsed since the last frame.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2017-11-13 23:32:14 +00:00
|
|
|
|
preUpdate: function (time, delta)
|
2017-03-29 00:12:14 +00:00
|
|
|
|
{
|
2017-11-13 23:32:14 +00:00
|
|
|
|
if (!this.runChildUpdate || this.children.size === 0)
|
2017-03-29 00:12:14 +00:00
|
|
|
|
{
|
2017-11-13 23:32:14 +00:00
|
|
|
|
return;
|
2017-03-29 00:12:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
// Because a Group child may mess with the length of the Group during its update
|
|
|
|
|
var temp = this.children.entries.slice();
|
2017-03-29 00:12:14 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
for (var i = 0; i < temp.length; i++)
|
2017-03-29 00:12:14 +00:00
|
|
|
|
{
|
2017-11-13 23:32:14 +00:00
|
|
|
|
var item = temp[i];
|
2017-03-29 00:12:14 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
if (item.active)
|
|
|
|
|
{
|
|
|
|
|
item.update(time, delta);
|
|
|
|
|
}
|
2017-03-29 00:12:14 +00:00
|
|
|
|
}
|
2017-11-13 23:32:14 +00:00
|
|
|
|
},
|
2017-03-29 00:12:14 +00:00
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Adds a Game Object to this group.
|
|
|
|
|
*
|
|
|
|
|
* Calls {@link Phaser.GameObjects.Group#createCallback}.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#add
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {Phaser.GameObjects.GameObject} child - The Game Object to add.
|
|
|
|
|
* @param {boolean} [addToScene=false] - Also add the Game Object to the scene.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @return {Phaser.GameObjects.Group} This Group object.
|
|
|
|
|
*/
|
2018-01-07 13:16:42 +00:00
|
|
|
|
add: function (child, addToScene)
|
2017-11-13 23:32:14 +00:00
|
|
|
|
{
|
2018-01-07 13:16:42 +00:00
|
|
|
|
if (addToScene === undefined) { addToScene = false; }
|
|
|
|
|
|
2018-04-13 16:59:29 +00:00
|
|
|
|
if (this.isFull())
|
|
|
|
|
{
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
this.children.set(child);
|
|
|
|
|
|
|
|
|
|
if (this.createCallback)
|
|
|
|
|
{
|
|
|
|
|
this.createCallback.call(this, child);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-07 13:16:42 +00:00
|
|
|
|
if (addToScene)
|
|
|
|
|
{
|
|
|
|
|
this.scene.sys.displayList.add(child);
|
|
|
|
|
|
|
|
|
|
if (child.preUpdate)
|
|
|
|
|
{
|
|
|
|
|
this.scene.sys.updateList.add(child);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-20 01:08:45 +00:00
|
|
|
|
child.on('destroy', this.remove, this);
|
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
return this;
|
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Adds several Game Objects to this group.
|
|
|
|
|
*
|
|
|
|
|
* Calls {@link Phaser.GameObjects.Group#createCallback}.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#addMultiple
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {Phaser.GameObjects.GameObject[]} children - The Game Objects to add.
|
|
|
|
|
* @param {boolean} [addToScene=false] - Also add the Game Objects to the scene.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @return {Phaser.GameObjects.Group} This group.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2018-01-07 13:16:42 +00:00
|
|
|
|
addMultiple: function (children, addToScene)
|
2017-11-13 23:32:14 +00:00
|
|
|
|
{
|
2018-01-07 13:16:42 +00:00
|
|
|
|
if (addToScene === undefined) { addToScene = false; }
|
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
if (Array.isArray(children))
|
|
|
|
|
{
|
|
|
|
|
for (var i = 0; i < children.length; i++)
|
|
|
|
|
{
|
2018-01-07 13:16:42 +00:00
|
|
|
|
this.add(children[i], addToScene);
|
2017-11-13 23:32:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this;
|
2017-03-29 00:12:14 +00:00
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Removes a member of this group.
|
|
|
|
|
*
|
|
|
|
|
* Calls {@link Phaser.GameObjects.Group#removeCallback}.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#remove
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {Phaser.GameObjects.GameObject} child - The Game Object to remove.
|
|
|
|
|
* @param {boolean} [removeFromScene=false] - Also remove the group member from the scene.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @return {Phaser.GameObjects.Group} This Group object.
|
|
|
|
|
*/
|
2018-01-07 13:16:42 +00:00
|
|
|
|
remove: function (child, removeFromScene)
|
2017-03-23 00:07:41 +00:00
|
|
|
|
{
|
2018-01-07 13:16:42 +00:00
|
|
|
|
if (removeFromScene === undefined) { removeFromScene = false; }
|
|
|
|
|
|
2017-03-27 15:59:51 +00:00
|
|
|
|
this.children.delete(child);
|
2017-03-23 00:07:41 +00:00
|
|
|
|
|
2018-03-21 11:19:31 +00:00
|
|
|
|
if (this.removeCallback)
|
|
|
|
|
{
|
|
|
|
|
this.removeCallback.call(this, child);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-07 13:16:42 +00:00
|
|
|
|
if (removeFromScene)
|
|
|
|
|
{
|
|
|
|
|
this.scene.sys.displayList.remove(child);
|
|
|
|
|
|
|
|
|
|
if (child.preUpdate)
|
|
|
|
|
{
|
|
|
|
|
this.scene.sys.updateList.remove(child);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-20 01:08:45 +00:00
|
|
|
|
child.off('destroy', this.remove, this);
|
|
|
|
|
|
2017-03-23 00:07:41 +00:00
|
|
|
|
return this;
|
2017-03-22 23:16:44 +00:00
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Removes all members of this group.
|
|
|
|
|
*
|
|
|
|
|
* Does not call {@link Phaser.GameObjects.Group#removeCallback}.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#clear
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {boolean} [removeFromScene=false] - Also remove each group member from the scene.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @return {Phaser.GameObjects.Group} This group.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2018-01-07 13:16:42 +00:00
|
|
|
|
clear: function (removeFromScene)
|
2017-03-23 00:07:41 +00:00
|
|
|
|
{
|
2018-01-07 13:16:42 +00:00
|
|
|
|
if (removeFromScene === undefined) { removeFromScene = false; }
|
|
|
|
|
|
2018-03-20 01:08:45 +00:00
|
|
|
|
var children = this.children;
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < children.size; i++)
|
2018-01-07 13:16:42 +00:00
|
|
|
|
{
|
2018-03-20 01:08:45 +00:00
|
|
|
|
var gameObject = children.entries[i];
|
2018-02-12 16:59:57 +00:00
|
|
|
|
|
2018-03-20 01:08:45 +00:00
|
|
|
|
gameObject.off('destroy', this.remove, this);
|
2018-01-07 13:16:42 +00:00
|
|
|
|
|
2018-03-20 01:08:45 +00:00
|
|
|
|
if (removeFromScene)
|
|
|
|
|
{
|
2018-01-07 13:16:42 +00:00
|
|
|
|
this.scene.sys.displayList.remove(gameObject);
|
|
|
|
|
|
|
|
|
|
if (gameObject.preUpdate)
|
|
|
|
|
{
|
|
|
|
|
this.scene.sys.updateList.remove(gameObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-27 15:59:51 +00:00
|
|
|
|
this.children.clear();
|
2017-03-23 00:07:41 +00:00
|
|
|
|
|
|
|
|
|
return this;
|
2017-03-22 23:16:44 +00:00
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Tests if a Game Object is a member of this group.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#contains
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {Phaser.GameObjects.GameObject} child - A Game Object.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @return {boolean} True if the Game Object is a member of this group.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2017-11-09 03:59:56 +00:00
|
|
|
|
contains: function (child)
|
|
|
|
|
{
|
|
|
|
|
return this.children.contains(child);
|
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* All members of the group.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#getChildren
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @return {Phaser.GameObjects.GameObject[]} The group members.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2017-04-07 14:44:04 +00:00
|
|
|
|
getChildren: function ()
|
|
|
|
|
{
|
|
|
|
|
return this.children.entries;
|
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* The number of members of the group.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#getLength
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @return {integer}
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2017-06-16 18:26:26 +00:00
|
|
|
|
getLength: function ()
|
|
|
|
|
{
|
|
|
|
|
return this.children.size;
|
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Scans the group for the first member that has an {@link Phaser.GameObjects.GameObject#active} state matching the argument,
|
|
|
|
|
* assigns `x` and `y`, and returns the member.
|
|
|
|
|
*
|
|
|
|
|
* If no matching member is found and `createIfNull` is true and the group isn't full then it will create a new Game Object using `x`, `y`, `key`, `frame`, and `visible`.
|
|
|
|
|
* Unless a new member is created, `key`, `frame`, and `visible` are ignored.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#getFirst
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {boolean} [state=false] - The {@link Phaser.GameObjects.GameObject#active} value to match.
|
|
|
|
|
* @param {boolean} [createIfNull=false] - Create a new Game Object if no matching members are found, using the following arguments.
|
|
|
|
|
* @param {number} [x] - The horizontal position of the Game Object in the world.
|
|
|
|
|
* @param {number} [y] - The vertical position of the Game Object in the world.
|
|
|
|
|
* @param {string} [key=defaultKey] - The texture key assigned to a new Game Object (if one is created).
|
|
|
|
|
* @param {(string|integer)} [frame=defaultFrame] - A texture frame assigned to a new Game Object (if one is created).
|
|
|
|
|
* @param {boolean} [visible=true] - The {@link Phaser.GameObjects.Components.Visible#visible} state of a new Game Object (if one is created).
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @return {?Phaser.GameObjects.GameObject} The first matching group member, or a newly created member, or null.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2017-11-13 23:32:14 +00:00
|
|
|
|
getFirst: function (state, createIfNull, x, y, key, frame, visible)
|
2017-06-19 13:38:22 +00:00
|
|
|
|
{
|
2017-11-13 23:32:14 +00:00
|
|
|
|
if (state === undefined) { state = false; }
|
|
|
|
|
if (createIfNull === undefined) { createIfNull = false; }
|
2017-06-19 13:38:22 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
var gameObject;
|
2017-06-19 13:38:22 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
var children = this.children.entries;
|
2017-03-28 02:09:59 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
for (var i = 0; i < children.length; i++)
|
|
|
|
|
{
|
2017-11-17 18:29:09 +00:00
|
|
|
|
gameObject = children[i];
|
2017-03-28 12:20:39 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
if (gameObject.active === state)
|
|
|
|
|
{
|
|
|
|
|
if (typeof(x) === 'number')
|
|
|
|
|
{
|
|
|
|
|
gameObject.x = x;
|
|
|
|
|
}
|
2017-03-29 15:04:51 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
if (typeof(y) === 'number')
|
|
|
|
|
{
|
|
|
|
|
gameObject.y = y;
|
|
|
|
|
}
|
2017-03-29 15:04:51 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
return gameObject;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-02 00:24:54 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
// Got this far? We need to create or bail
|
|
|
|
|
if (createIfNull)
|
|
|
|
|
{
|
|
|
|
|
return this.create(x, y, key, frame, visible);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2017-08-02 00:24:54 +00:00
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Scans the group for the first member that has an {@link Phaser.GameObjects.GameObject#active} state set to `false`,
|
|
|
|
|
* assigns `x` and `y`, and returns the member.
|
|
|
|
|
*
|
|
|
|
|
* If no inactive member is found and the group isn't full then it will create a new Game Object using `x`, `y`, `key`, `frame`, and `visible`.
|
|
|
|
|
* The new Game Object will have its active state set to `true`.
|
|
|
|
|
* Unless a new member is created, `key`, `frame`, and `visible` are ignored.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#get
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {number} [x] - The horizontal position of the Game Object in the world.
|
|
|
|
|
* @param {number} [y] - The vertical position of the Game Object in the world.
|
|
|
|
|
* @param {string} [key=defaultKey] - The texture key assigned to a new Game Object (if one is created).
|
|
|
|
|
* @param {(string|integer)} [frame=defaultFrame] - A texture frame assigned to a new Game Object (if one is created).
|
|
|
|
|
* @param {boolean} [visible=true] - The {@link Phaser.GameObjects.Components.Visible#visible} state of a new Game Object (if one is created).
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @return {?Phaser.GameObjects.GameObject} The first inactive group member, or a newly created member, or null.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2017-11-13 23:32:14 +00:00
|
|
|
|
get: function (x, y, key, frame, visible)
|
2017-03-29 15:04:51 +00:00
|
|
|
|
{
|
2017-11-13 23:32:14 +00:00
|
|
|
|
return this.getFirst(false, true, x, y, key, frame, visible);
|
2017-03-28 12:20:39 +00:00
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Scans the group for the first member that has an {@link Phaser.GameObjects.GameObject#active} state set to `true`,
|
|
|
|
|
* assigns `x` and `y`, and returns the member.
|
|
|
|
|
*
|
|
|
|
|
* If no active member is found and `createIfNull` is `true` and the group isn't full then it will create a new one using `x`, `y`, `key`, `frame`, and `visible`.
|
|
|
|
|
* Unless a new member is created, `key`, `frame`, and `visible` are ignored.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#getFirstAlive
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {boolean} [createIfNull=false] - Create a new Game Object if no matching members are found, using the following arguments.
|
|
|
|
|
* @param {number} [x] - The horizontal position of the Game Object in the world.
|
|
|
|
|
* @param {number} [y] - The vertical position of the Game Object in the world.
|
|
|
|
|
* @param {string} [key=defaultKey] - The texture key assigned to a new Game Object (if one is created).
|
|
|
|
|
* @param {(string|integer)} [frame=defaultFrame] - A texture frame assigned to a new Game Object (if one is created).
|
|
|
|
|
* @param {boolean} [visible=true] - The {@link Phaser.GameObjects.Components.Visible#visible} state of a new Game Object (if one is created).
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @return {Phaser.GameObjects.GameObject} The first active group member, or a newly created member, or null.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2017-11-13 23:32:14 +00:00
|
|
|
|
getFirstAlive: function (createIfNull, x, y, key, frame, visible)
|
2017-03-29 16:11:26 +00:00
|
|
|
|
{
|
2017-11-13 23:32:14 +00:00
|
|
|
|
return this.getFirst(true, createIfNull, x, y, key, frame, visible);
|
2017-03-29 16:11:26 +00:00
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Scans the group for the first member that has an {@link Phaser.GameObjects.GameObject#active} state set to `false`,
|
|
|
|
|
* assigns `x` and `y`, and returns the member.
|
|
|
|
|
*
|
|
|
|
|
* If no inactive member is found and `createIfNull` is `true` and the group isn't full then it will create a new one using `x`, `y`, `key`, `frame`, and `visible`.
|
|
|
|
|
* The new Game Object will have an active state set to `true`.
|
|
|
|
|
* Unless a new member is created, `key`, `frame`, and `visible` are ignored.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#getFirstDead
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {boolean} [createIfNull=false] - Create a new Game Object if no matching members are found, using the following arguments.
|
|
|
|
|
* @param {number} [x] - The horizontal position of the Game Object in the world.
|
|
|
|
|
* @param {number} [y] - The vertical position of the Game Object in the world.
|
|
|
|
|
* @param {string} [key=defaultKey] - The texture key assigned to a new Game Object (if one is created).
|
|
|
|
|
* @param {(string|integer)} [frame=defaultFrame] - A texture frame assigned to a new Game Object (if one is created).
|
|
|
|
|
* @param {boolean} [visible=true] - The {@link Phaser.GameObjects.Components.Visible#visible} state of a new Game Object (if one is created).
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @return {Phaser.GameObjects.GameObject} The first inactive group member, or a newly created member, or null.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2017-11-13 23:32:14 +00:00
|
|
|
|
getFirstDead: function (createIfNull, x, y, key, frame, visible)
|
2017-03-30 23:46:19 +00:00
|
|
|
|
{
|
2017-11-13 23:32:14 +00:00
|
|
|
|
return this.getFirst(false, createIfNull, x, y, key, frame, visible);
|
2017-03-30 23:46:19 +00:00
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* {@link Phaser.GameObjects.Components.Animation#play Plays} an animation for all members of this group.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#playAnimation
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {string} key - The string-based key of the animation to play.
|
|
|
|
|
* @param {string} [startFrame=0] - Optionally start the animation playing from this frame index.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @return {Phaser.GameObjects.Group} This Group object.
|
|
|
|
|
*/
|
2017-04-08 00:59:44 +00:00
|
|
|
|
playAnimation: function (key, startFrame)
|
|
|
|
|
{
|
|
|
|
|
Actions.PlayAnimation(this.children.entries, key, startFrame);
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Whether this group's size at its {@link Phaser.GameObjects.Group#maxSize maximum}.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#isFull
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @return {boolean} True if the number of members equals {@link Phaser.GameObjects.Group#maxSize}.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2017-11-13 23:32:14 +00:00
|
|
|
|
isFull: function ()
|
2017-03-28 13:30:43 +00:00
|
|
|
|
{
|
2017-11-13 23:32:14 +00:00
|
|
|
|
if (this.maxSize === -1)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return (this.children.size === this.maxSize);
|
|
|
|
|
}
|
2017-03-28 12:20:39 +00:00
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Counts the number of active (or inactive) group members.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#countActive
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {boolean} [value=true] - Count active (true) or inactive (false) group members.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @return {integer} The number of group members with an active state matching the `active` argument.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2017-12-03 17:12:22 +00:00
|
|
|
|
countActive: function (value)
|
2017-03-28 12:20:39 +00:00
|
|
|
|
{
|
2017-12-03 17:12:22 +00:00
|
|
|
|
if (value === undefined) { value = true; }
|
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
var total = 0;
|
2017-03-28 12:20:39 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
for (var i = 0; i < this.children.size; i++)
|
|
|
|
|
{
|
2017-12-03 17:12:22 +00:00
|
|
|
|
if (this.children.entries[i].active === value)
|
2017-11-13 23:32:14 +00:00
|
|
|
|
{
|
|
|
|
|
total++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-28 12:20:39 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
return total;
|
2017-03-28 12:20:39 +00:00
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Counts the number of in-use (active) group members.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#getTotalUsed
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @return {integer} The number of group members with an active state of true.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2017-12-03 17:12:22 +00:00
|
|
|
|
getTotalUsed: function ()
|
|
|
|
|
{
|
|
|
|
|
return this.countActive();
|
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* The difference of {@link Phaser.GameObjects.Group#maxSize} and the number of active group members.
|
|
|
|
|
*
|
|
|
|
|
* This represents the number of group members that could be created or reactivated before reaching the size limit.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#getTotalFree
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @return {integer} maxSize minus the number of active group numbers; or a large number (if maxSize is -1).
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2017-11-13 23:32:14 +00:00
|
|
|
|
getTotalFree: function ()
|
2017-03-28 12:20:39 +00:00
|
|
|
|
{
|
2017-11-13 23:32:14 +00:00
|
|
|
|
var used = this.getTotalUsed();
|
|
|
|
|
var capacity = (this.maxSize === -1) ? 999999999999 : this.maxSize;
|
2017-03-28 12:20:39 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
return (capacity - used);
|
2017-03-28 12:20:39 +00:00
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Sets the depth of each group member.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#setDepth
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {number} value - The amount to set the property to.
|
|
|
|
|
* @param {number} step - This is added to the `value` amount, multiplied by the iteration counter.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @return {Phaser.GameObjects.Group} This Group object.
|
|
|
|
|
*/
|
2017-09-14 02:12:00 +00:00
|
|
|
|
setDepth: function (value, step)
|
2017-06-28 13:16:01 +00:00
|
|
|
|
{
|
2017-09-14 02:12:00 +00:00
|
|
|
|
Actions.SetDepth(this.children.entries, value, step);
|
2017-06-28 13:16:01 +00:00
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Deactivates a member of this group.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#kill
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {Phaser.GameObjects.GameObject} gameObject - A member of this group.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2017-11-13 23:32:14 +00:00
|
|
|
|
kill: function (gameObject)
|
2017-03-28 14:33:20 +00:00
|
|
|
|
{
|
2017-11-13 23:32:14 +00:00
|
|
|
|
if (this.children.contains(gameObject))
|
|
|
|
|
{
|
|
|
|
|
gameObject.setActive(false);
|
|
|
|
|
}
|
2017-03-28 14:33:20 +00:00
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Deactivates and hides a member of this group.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#killAndHide
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {Phaser.GameObjects.GameObject} gameObject - A member of this group.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2017-11-13 23:32:14 +00:00
|
|
|
|
killAndHide: function (gameObject)
|
2017-03-28 14:33:20 +00:00
|
|
|
|
{
|
2017-11-13 23:32:14 +00:00
|
|
|
|
if (this.children.contains(gameObject))
|
|
|
|
|
{
|
|
|
|
|
gameObject.setActive(false);
|
|
|
|
|
gameObject.setVisible(false);
|
|
|
|
|
}
|
2017-03-28 14:33:20 +00:00
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Toggles (flips) the visible state of each member of this group.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#toggleVisible
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*
|
|
|
|
|
* @return {Phaser.GameObjects.Group} This Group object.
|
|
|
|
|
*/
|
2017-11-13 23:32:14 +00:00
|
|
|
|
toggleVisible: function ()
|
2017-03-28 14:33:20 +00:00
|
|
|
|
{
|
2017-11-13 23:32:14 +00:00
|
|
|
|
Actions.ToggleVisible(this.children.entries);
|
2017-03-28 14:33:20 +00:00
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
},
|
|
|
|
|
|
2018-02-12 17:21:06 +00:00
|
|
|
|
/**
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* Empties this group and removes it from the scene.
|
|
|
|
|
*
|
|
|
|
|
* Does not call {@link Phaser.GameObjects.Group#removeCallback}.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @method Phaser.GameObjects.Group#destroy
|
|
|
|
|
* @since 3.0.0
|
2018-03-27 00:09:30 +00:00
|
|
|
|
*
|
2018-04-13 03:10:03 +00:00
|
|
|
|
* @param {boolean} [destroyChildren=false] - Also {@link Phaser.GameObjects.GameObject#destroy} each group member.
|
2018-02-12 17:21:06 +00:00
|
|
|
|
*/
|
2018-03-27 00:09:30 +00:00
|
|
|
|
destroy: function (destroyChildren)
|
2017-03-28 12:20:39 +00:00
|
|
|
|
{
|
2018-03-27 00:09:30 +00:00
|
|
|
|
if (destroyChildren === undefined) { destroyChildren = false; }
|
|
|
|
|
|
|
|
|
|
if (destroyChildren)
|
|
|
|
|
{
|
|
|
|
|
var children = this.children;
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < children.size; i++)
|
|
|
|
|
{
|
|
|
|
|
var gameObject = children.entries[i];
|
|
|
|
|
|
|
|
|
|
// Remove the event hook first or it'll go all recursive hell on us
|
|
|
|
|
gameObject.off('destroy', this.remove, this);
|
|
|
|
|
|
|
|
|
|
gameObject.destroy();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
this.children.clear();
|
2017-03-28 12:20:39 +00:00
|
|
|
|
|
2017-11-13 23:32:14 +00:00
|
|
|
|
this.scene = undefined;
|
|
|
|
|
this.children = undefined;
|
2017-03-28 12:20:39 +00:00
|
|
|
|
}
|
2017-03-28 02:09:59 +00:00
|
|
|
|
|
2017-03-22 23:16:44 +00:00
|
|
|
|
});
|
|
|
|
|
|
2017-06-26 20:08:08 +00:00
|
|
|
|
module.exports = Group;
|