Skip to content

Commit 18a924c

Browse files
committed
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 phaserjs#4511
1 parent 068c1a7 commit 18a924c

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
* `ArcadePhysics.furthest` now iterates the bodies Set, rather than the RTree, which keeps it working even if the RTree has been disabled.
4949
* `ArcadePhysics.closest` now iterates the bodies Set, rather than the RTree, which keeps it working even if the RTree has been disabled.
5050
* `Body.setVelocity` caused the `speed` property to be set to `NaN` if you didn't provide a `y` argument.
51+
* 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)
5152

5253
### Facebook Instant Games Plugin
5354

src/gameobjects/group/Group.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,16 @@ var Group = new Class({
352352
yoyo: yoyo
353353
});
354354

355+
if (options.createCallback)
356+
{
357+
this.createCallback = options.createCallback;
358+
}
359+
360+
if (options.removeCallback)
361+
{
362+
this.removeCallback = options.removeCallback;
363+
}
364+
355365
for (var c = 0; c < range.length; c++)
356366
{
357367
var created = this.create(0, 0, range[c].a, range[c].b, visible, active);

src/physics/arcade/PhysicsGroup.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ var PhysicsGroup = new Class({
5757
else if (Array.isArray(children) && IsPlainObject(children[0]))
5858
{
5959
// children is an array of plain objects
60-
config = children;
61-
children = null;
60+
config = children[0];
61+
62+
var _this = this;
6263

63-
config.forEach(function (singleConfig)
64+
children.forEach(function (singleConfig)
6465
{
65-
singleConfig.createCallback = this.createCallbackHandler;
66-
singleConfig.removeCallback = this.removeCallbackHandler;
66+
singleConfig.createCallback = _this.createCallbackHandler;
67+
singleConfig.removeCallback = _this.removeCallbackHandler;
6768
});
6869
}
6970
else
@@ -138,6 +139,11 @@ var PhysicsGroup = new Class({
138139
setImmovable: GetFastValue(config, 'immovable', false)
139140
};
140141

142+
if (Array.isArray(children))
143+
{
144+
config = null;
145+
}
146+
141147
Group.call(this, scene, children, config);
142148
},
143149

0 commit comments

Comments
 (0)