Skip to content

Commit 713bd20

Browse files
committed
ArcadePhysics.collideSpriteVsGroup checks if Sprite has a body before carrying on, now safely skips sub-groups or other non-Sprite group children.
QuadTree.retrieve now checks to see if the given Sprite has a body before carrying on.
1 parent ce592d4 commit 713bd20

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ Version 2.0.4 - "Mos Shirare" - in development
6666
* AnimationManager.play will now call Animation.stop on the current animation before switching to the new one (thanks @nihakue, #713)
6767
* ArcadePhysics.Body.phase is checked in postUpdate to prevent it from being called multiple times in a single frame.
6868
* Group.setProperty will now check if the property exists before setting it, this applies to Group.setAll and anything else using setProperty internally.
69+
* QuadTree.retrieve now checks to see if the given Sprite has a body before carrying on.
70+
* ArcadePhysics.collideSpriteVsGroup checks if Sprite has a body before carrying on, now safely skips sub-groups or other non-Sprite group children.
71+
6972

7073

7174
### New Features

src/math/QuadTree.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ Phaser.QuadTree = function(x, y, width, height, maxObjects, maxLevels, level) {
9191
*/
9292
this.nodes = [];
9393

94+
/**
95+
* @property {array} _empty - Internal empty array.
96+
* @private
97+
*/
98+
this._empty = [];
99+
94100
this.reset(x, y, width, height, maxObjects, maxLevels, level);
95101

96102
};
@@ -286,9 +292,13 @@ Phaser.QuadTree.prototype = {
286292
*/
287293
retrieve: function (sprite) {
288294

295+
if (!sprite.body)
296+
{
297+
return this._empty;
298+
}
299+
289300
var returnObjects = this.objects;
290301

291-
// sprite.body.quadTreeIndex = this.getIndex(sprite.body);
292302
var index = this.getIndex(sprite.body);
293303

294304
if (this.nodes[0])

src/physics/arcade/World.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ Phaser.Physics.Arcade.prototype = {
543543
*/
544544
collideSpriteVsGroup: function (sprite, group, collideCallback, processCallback, callbackContext, overlapOnly) {
545545

546-
if (group.length === 0)
546+
if (group.length === 0 || !sprite.body)
547547
{
548548
return;
549549
}
@@ -650,6 +650,11 @@ Phaser.Physics.Arcade.prototype = {
650650
*/
651651
collideSpriteVsTilemapLayer: function (sprite, tilemapLayer, collideCallback, processCallback, callbackContext) {
652652

653+
if (!sprite.body)
654+
{
655+
return;
656+
}
657+
653658
this._mapData = tilemapLayer.getTiles(
654659
sprite.body.position.x - sprite.body.tilePadding.x,
655660
sprite.body.position.y - sprite.body.tilePadding.y,

0 commit comments

Comments
 (0)