Merge pull request #1314 from pjbaron/dev

getObjectsAtLocation method for Arcade Physics
This commit is contained in:
Richard Davey 2014-11-12 00:30:09 +00:00
commit 52a39cd123
2 changed files with 24 additions and 5 deletions

View file

@ -1407,24 +1407,43 @@ Phaser.Physics.Arcade.prototype = {
return;
}
return this.getObjectsAtLocation(pointer.x, pointer.y, group, callback, callbackContext, pointer);
},
/**
* Given a Group and a location this will check to see which Group children overlap with the coordinates.
* Each child will be sent to the given callback for further processing.
* Note that the children are not checked for depth order, but simply if they overlap the coordinate or not.
*
* @method Phaser.Physics.Arcade#getObjectsAtLocation
* @param {Phaser.Pointer} pointer - The Pointer to check.
* @param {Phaser.Group} group - The Group to check.
* @param {function} [callback] - A callback function that is called if the object overlaps the coordinates. The callback will be sent two parameters: the callbackArg and the Object that overlapped the location.
* @param {object} [callbackContext] - The context in which to run the callback.
* @param {object} [callbackArg] - An argument to pass to the callback.
* @return {array} An array of the Sprites from the Group that overlapped the coordinates.
*/
getObjectsAtLocation: function (x, y, group, callback, callbackContext, callbackArg) {
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);
var rect = new Phaser.Rectangle(pointer.x, pointer.y, 1, 1);
var rect = new Phaser.Rectangle(x, y, 1, 1);
var output = [];
this._potentials = this.quadTree.retrieve(rect);
for (var i = 0, len = this._potentials.length; i < len; i++)
{
if (this._potentials[i].hitTest(pointer.x, pointer.y))
if (this._potentials[i].hitTest(x, y))
{
if (callback)
{
callback.call(callbackContext, pointer, this._potentials[i].sprite);
callback.call(callbackContext, callbackArg, this._potentials[i].sprite);
}
output.push(this._potentials[i].sprite);
@ -1432,7 +1451,7 @@ Phaser.Physics.Arcade.prototype = {
}
return output;
},
/**

View file

@ -449,4 +449,4 @@ Phaser.Time.prototype = {
};
Phaser.Time.prototype.constructor = Phaser.Time;
Phaser.Time.prototype.constructor = Phaser.Time;