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.
This commit is contained in:
photonstorm 2014-04-17 12:31:14 +01:00
parent ce592d48bf
commit 713bd203ee
3 changed files with 20 additions and 2 deletions

View file

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

View file

@ -91,6 +91,12 @@ Phaser.QuadTree = function(x, y, width, height, maxObjects, maxLevels, level) {
*/ */
this.nodes = []; this.nodes = [];
/**
* @property {array} _empty - Internal empty array.
* @private
*/
this._empty = [];
this.reset(x, y, width, height, maxObjects, maxLevels, level); this.reset(x, y, width, height, maxObjects, maxLevels, level);
}; };
@ -286,9 +292,13 @@ Phaser.QuadTree.prototype = {
*/ */
retrieve: function (sprite) { retrieve: function (sprite) {
if (!sprite.body)
{
return this._empty;
}
var returnObjects = this.objects; var returnObjects = this.objects;
// sprite.body.quadTreeIndex = this.getIndex(sprite.body);
var index = this.getIndex(sprite.body); var index = this.getIndex(sprite.body);
if (this.nodes[0]) if (this.nodes[0])

View file

@ -543,7 +543,7 @@ Phaser.Physics.Arcade.prototype = {
*/ */
collideSpriteVsGroup: function (sprite, group, collideCallback, processCallback, callbackContext, overlapOnly) { collideSpriteVsGroup: function (sprite, group, collideCallback, processCallback, callbackContext, overlapOnly) {
if (group.length === 0) if (group.length === 0 || !sprite.body)
{ {
return; return;
} }
@ -650,6 +650,11 @@ Phaser.Physics.Arcade.prototype = {
*/ */
collideSpriteVsTilemapLayer: function (sprite, tilemapLayer, collideCallback, processCallback, callbackContext) { collideSpriteVsTilemapLayer: function (sprite, tilemapLayer, collideCallback, processCallback, callbackContext) {
if (!sprite.body)
{
return;
}
this._mapData = tilemapLayer.getTiles( this._mapData = tilemapLayer.getTiles(
sprite.body.position.x - sprite.body.tilePadding.x, sprite.body.position.x - sprite.body.tilePadding.x,
sprite.body.position.y - sprite.body.tilePadding.y, sprite.body.position.y - sprite.body.tilePadding.y,