Skip to content

Commit

Permalink
Passing an _array_ of configuration objects to physics.add.group wo…
Browse files Browse the repository at this point in the history
…uld ignore them and none of the children would be assigned a physics body. Fix #4511
  • Loading branch information
photonstorm committed May 7, 2019
1 parent 068c1a7 commit 18a924c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -48,6 +48,7 @@
* `ArcadePhysics.furthest` now iterates the bodies Set, rather than the RTree, which keeps it working even if the RTree has been disabled.
* `ArcadePhysics.closest` now iterates the bodies Set, rather than the RTree, which keeps it working even if the RTree has been disabled.
* `Body.setVelocity` caused the `speed` property to be set to `NaN` if you didn't provide a `y` argument.
* Passing an _array_ of configuration objects to `physics.add.group` would ignore them and none of the children would be assigned a physics body. Fix #4511 (thanks @rgk)

### Facebook Instant Games Plugin

Expand Down
10 changes: 10 additions & 0 deletions src/gameobjects/group/Group.js
Expand Up @@ -352,6 +352,16 @@ var Group = new Class({
yoyo: yoyo
});

if (options.createCallback)
{
this.createCallback = options.createCallback;
}

if (options.removeCallback)
{
this.removeCallback = options.removeCallback;
}

for (var c = 0; c < range.length; c++)
{
var created = this.create(0, 0, range[c].a, range[c].b, visible, active);
Expand Down
16 changes: 11 additions & 5 deletions src/physics/arcade/PhysicsGroup.js
Expand Up @@ -57,13 +57,14 @@ var PhysicsGroup = new Class({
else if (Array.isArray(children) && IsPlainObject(children[0]))
{
// children is an array of plain objects
config = children;
children = null;
config = children[0];

var _this = this;

config.forEach(function (singleConfig)
children.forEach(function (singleConfig)
{
singleConfig.createCallback = this.createCallbackHandler;
singleConfig.removeCallback = this.removeCallbackHandler;
singleConfig.createCallback = _this.createCallbackHandler;
singleConfig.removeCallback = _this.removeCallbackHandler;
});
}
else
Expand Down Expand Up @@ -138,6 +139,11 @@ var PhysicsGroup = new Class({
setImmovable: GetFastValue(config, 'immovable', false)
};

if (Array.isArray(children))
{
config = null;
}

Group.call(this, scene, children, config);
},

Expand Down

0 comments on commit 18a924c

Please sign in to comment.