Arcade Physics Body.skipQuadTree is a new boolean that if set to true when you collide the Sprite against a Group it will tell Phaser to skip using a QuadTree for that collision. This is handy if this Body is especially large.

Arcade Physics World.skipQuadTree will disable the use of all QuadTrees in collision methods, which can help performance in tightly packed scenes.
This commit is contained in:
photonstorm 2014-08-04 13:04:11 +01:00
parent 06cb37247a
commit 36ecd81f29
3 changed files with 41 additions and 16 deletions

View file

@ -53,6 +53,8 @@ Version 2.1.0 - "Cairhien" - -in development-
### New Features
* Device will now detect for Kindle and PS Vita (thanks @lucbloom)
* Arcade Physics Body.skipQuadTree is a new boolean that if set to `true` when you collide the Sprite against a Group it will tell Phaser to skip using a QuadTree for that collision. This is handy if this Body is especially large.
* Arcade Physics World.skipQuadTree will disable the use of all QuadTrees in collision methods, which can help performance in tightly packed scenes.
### Bug Fixes
@ -98,7 +100,7 @@ You can [clone the Phaser repo in Koding](https://koding.com/Teamwork?import=htt
If you use bower you can install phaser with:
`bower install phaser-official`
`bower install phaser`
Nice and easy :)

View file

@ -297,6 +297,11 @@ Phaser.Physics.Arcade.Body = function (sprite) {
*/
this.phase = 0;
/**
* @property {boolean} skipQuadTree - If true and you collide this Sprite against a Group, it will disable the collision check from using a QuadTree.
*/
this.skipQuadTree = false;
/**
* @property {boolean} _reset - Internal cache var.
* @private

View file

@ -61,6 +61,11 @@ Phaser.Physics.Arcade = function (game) {
*/
this.forceX = false;
/**
* @property {boolean} skipQuadTree - If true a QuadTree will never be used for any collision. Handy for tightly packed games. See also Body.skipQuadTree.
*/
this.skipQuadTree = false;
/**
* @property {Phaser.QuadTree} quadTree - The world QuadTree.
*/
@ -553,26 +558,39 @@ Phaser.Physics.Arcade.prototype = {
return;
}
// What is the sprite colliding with in the quadtree?
this.quadTree.clear();
this.quadTree.reset(this.game.world.bounds.x, this.game.world.bounds.y, this.game.world.bounds.width, this.game.world.bounds.height, this.maxObjects, this.maxLevels);
this.quadTree.populate(group);
this._potentials = this.quadTree.retrieve(sprite);
for (var i = 0, len = this._potentials.length; i < len; i++)
if (sprite.body.skipQuadTree || this.skipQuadTree)
{
// We have our potential suspects, are they in this group?
if (this.separate(sprite.body, this._potentials[i], processCallback, callbackContext, overlapOnly))
for (var i = 0, len = group.children.length; i < len; i++)
{
if (collideCallback)
if (group.children[i] && group.children[i].exists)
{
collideCallback.call(callbackContext, sprite, this._potentials[i].sprite);
this.collideSpriteVsSprite(sprite, group.children[i], collideCallback, processCallback, callbackContext, overlapOnly);
}
}
}
else
{
// What is the sprite colliding with in the quadtree?
this.quadTree.clear();
this._total++;
this.quadTree.reset(this.game.world.bounds.x, this.game.world.bounds.y, this.game.world.bounds.width, this.game.world.bounds.height, this.maxObjects, this.maxLevels);
this.quadTree.populate(group);
this._potentials = this.quadTree.retrieve(sprite);
for (var i = 0, len = this._potentials.length; i < len; i++)
{
// We have our potential suspects, are they in this group?
if (this.separate(sprite.body, this._potentials[i], processCallback, callbackContext, overlapOnly))
{
if (collideCallback)
{
collideCallback.call(callbackContext, sprite, this._potentials[i].sprite);
}
this._total++;
}
}
}