Skip to content

Commit

Permalink
enableBody added to Group constructor. Also: game.add.physicsGroup(Ph…
Browse files Browse the repository at this point in the history
…aser.Physics.ARCADE) is a thing :)
  • Loading branch information
photonstorm committed Mar 13, 2014
1 parent 6b55fea commit 39add47
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
11 changes: 7 additions & 4 deletions src/core/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
* @param {Phaser.Group|Phaser.Sprite|null} parent - The parent Group, DisplayObject or DisplayObjectContainer that this Group will be added to. If undefined it will use game.world. If null it won't be added to anything.
* @param {string} [name=group] - A name for this Group. Not used internally but useful for debugging.
* @param {boolean} [addToStage=false] - If set to true this Group will be added directly to the Game.Stage instead of Game.World.
* @param {boolean} [enableBody=false] - If true all Sprites created with `Group.create` or `Group.createMulitple` will have a physics body created on them. Change the body type with physicsBodyType.
* @param {number} [physicsBodyType=0] - If enableBody is true this is the type of physics body that is created on new Sprites. Phaser.Physics.ARCADE, Phaser.Physics.P2, Phaser.Physics.NINJA, etc.
*/
Phaser.Group = function (game, parent, name, addToStage) {
Phaser.Group = function (game, parent, name, addToStage, enableBody, physicsBodyType) {

if (typeof addToStage === 'undefined') { addToStage = false; }
if (typeof enableBody === 'undefined') { enableBody = false; }
if (typeof physicsBodyType === 'undefined') { physicsBodyType = Phaser.Physics.ARCADE; }

/**
* @property {Phaser.Game} game - A reference to the currently running Game.
Expand Down Expand Up @@ -103,14 +107,13 @@ Phaser.Group = function (game, parent, name, addToStage) {

/**
* @property {boolean} enableBodyDebug - If true when a physics body is created (via Group.enableBody) it will create a physics debug object as well. Only works for P2 bodies.
* @default
*/
this.enableBodyDebug = false;
this.enableBodyDebug = enableBody;

/**
* @property {number} physicsBodyType - If Group.enableBody is true this is the type of physics body that is created on new Sprites. Phaser.Physics.ARCADE, Phaser.Physics.P2, Phaser.Physics.NINJA, etc.
*/
this.physicsBodyType = Phaser.Physics.ARCADE;
this.physicsBodyType = physicsBodyType;

/**
* @property {string} _sortProperty - The property on which children are sorted.
Expand Down
10 changes: 4 additions & 6 deletions src/gameobjects/GameObjectCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,15 @@ Phaser.GameObjectCreator.prototype = {
* A Group is a container for display objects that allows for fast pooling, recycling and collision checks.
*
* @method Phaser.GameObjectCreator#group
* @param {any} [parent] - The parent Group or DisplayObjectContainer that will hold this group, if any. If set to null the Group won't be added to the display list. If undefined it will be added to World by default.
* @param {string} [name='group'] - A name for this Group. Not used internally but useful for debugging.
* @param {boolean} [addToStage=false] - If set to true this Group will be added directly to the Game.Stage instead of Game.World.
* @param {boolean} [enableBody=false] - If true all Sprites created with `Group.create` or `Group.createMulitple` will have a physics body created on them. Change the body type with physicsBodyType.
* @param {number} [physicsBodyType=0] - If enableBody is true this is the type of physics body that is created on new Sprites. Phaser.Physics.ARCADE, Phaser.Physics.P2, Phaser.Physics.NINJA, etc.
* @return {Phaser.Group} The newly created group.
*/
group: function (parent, name, addToStage) {
group: function (parent, name, addToStage, enableBody, physicsBodyType) {

if (typeof name === 'undefined') { name = 'group'; }
if (typeof addToStage === 'undefined') { addToStage = false; }

return new Phaser.Group(this.game, parent, name, addToStage);
return new Phaser.Group(this.game, null, name, addToStage, enableBody, physicsBodyType);

},

Expand Down
25 changes: 21 additions & 4 deletions src/gameobjects/GameObjectFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,31 @@ Phaser.GameObjectFactory.prototype = {
* @param {any} [parent] - The parent Group or DisplayObjectContainer that will hold this group, if any. If set to null the Group won't be added to the display list. If undefined it will be added to World by default.
* @param {string} [name='group'] - A name for this Group. Not used internally but useful for debugging.
* @param {boolean} [addToStage=false] - If set to true this Group will be added directly to the Game.Stage instead of Game.World.
* @param {boolean} [enableBody=false] - If true all Sprites created with `Group.create` or `Group.createMulitple` will have a physics body created on them. Change the body type with physicsBodyType.
* @param {number} [physicsBodyType=0] - If enableBody is true this is the type of physics body that is created on new Sprites. Phaser.Physics.ARCADE, Phaser.Physics.P2, Phaser.Physics.NINJA, etc.
* @return {Phaser.Group} The newly created group.
*/
group: function (parent, name, addToStage) {
group: function (parent, name, addToStage, enableBody, physicsBodyType) {

if (typeof name === 'undefined') { name = 'group'; }
if (typeof addToStage === 'undefined') { addToStage = false; }
return new Phaser.Group(this.game, parent, name, addToStage, enableBody, physicsBodyType);

},

/**
* A Group is a container for display objects that allows for fast pooling, recycling and collision checks.
* A Physics Group is the same as an ordinary Group except that is has enableBody turned on by default, so any Sprites it creates
* are automatically given a physics body.
*
* @method Phaser.GameObjectFactory#group
* @param {number} [physicsBodyType=Phaser.Physics.ARCADE] - If enableBody is true this is the type of physics body that is created on new Sprites. Phaser.Physics.ARCADE, Phaser.Physics.P2, Phaser.Physics.NINJA, etc.
* @param {any} [parent] - The parent Group or DisplayObjectContainer that will hold this group, if any. If set to null the Group won't be added to the display list. If undefined it will be added to World by default.
* @param {string} [name='group'] - A name for this Group. Not used internally but useful for debugging.
* @param {boolean} [addToStage=false] - If set to true this Group will be added directly to the Game.Stage instead of Game.World.
* @return {Phaser.Group} The newly created group.
*/
physicsGroup: function (physicsBodyType, parent, name, addToStage) {

return new Phaser.Group(this.game, parent, name, addToStage);
return new Phaser.Group(this.game, parent, name, addToStage, true, physicsBodyType);

},

Expand Down

0 comments on commit 39add47

Please sign in to comment.