mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 20:53:39 +00:00
Added the new overlapRect
method.
This commit is contained in:
parent
8e872fcb51
commit
8839ab1c0e
2 changed files with 73 additions and 2 deletions
|
@ -6,8 +6,9 @@
|
|||
|
||||
#### New Features
|
||||
|
||||
* `World.overlapTiles` is a new method that allows you to check for overlaps between a physics enabled Game Object and an array of Tiles. The Tiles don't have to have been enable for collision, or even be on the same layer, for the overlap check to work. You can provide your own process callback and/or overlap callback. This is handy for testing for overlap for a specific Tile in your map, not just based on a tile index. This is also available via `this.physics.overlapTiles`.
|
||||
* `World.collideTiles` is a new method that allows you to check for collision between a physics enabled Game Object and an array of Tiles. The Tiles don't have to have been enable for collision, or even be on the same layer, for the collision to work. You can provide your own process callback and/or overlap callback. There are some limitations in using this method, please consult the API Docs for details, but on the whole, it allows for dynamic collision on small sets of Tile instances. This is also available via `this.physics.collideTiles`.
|
||||
* `overlapTiles` is a new method that allows you to check for overlaps between a physics enabled Game Object and an array of Tiles. The Tiles don't have to have been enable for collision, or even be on the same layer, for the overlap check to work. You can provide your own process callback and/or overlap callback. This is handy for testing for overlap for a specific Tile in your map, not just based on a tile index. This is available via `this.physics.overlapTiles` and the World instance.
|
||||
* `collideTiles` is a new method that allows you to check for collision between a physics enabled Game Object and an array of Tiles. The Tiles don't have to have been enable for collision, or even be on the same layer, for the collision to work. You can provide your own process callback and/or overlap callback. There are some limitations in using this method, please consult the API Docs for details, but on the whole, it allows for dynamic collision on small sets of Tile instances. This is available via `this.physics.collideTiles` and the World instance.
|
||||
* `overlapRect` is a new method that allows you to return an array of all physics bodies within the given rectangular region of the World. It can return dynamic or static bodies and will use the RTree for super-fast searching, if enabled (which it is by default)
|
||||
|
||||
#### Updates
|
||||
|
||||
|
|
|
@ -519,6 +519,76 @@ var ArcadePhysics = new Class({
|
|||
return vec2.setToPolar(rotation, speed);
|
||||
},
|
||||
|
||||
/**
|
||||
* This method will search the given rectangular area and return an array of all physics bodies that
|
||||
* overlap with it. It can return either Dynamic or Static bodies. If Arcade Physics is set to use
|
||||
* the RTree (which it is by default) then the search is extremely fast, otherwise the search is O(N).
|
||||
*
|
||||
* @method Phaser.Physics.Arcade.ArcadePhysics#overlapRect
|
||||
* @since 3.17.0
|
||||
*
|
||||
* @param {number} x - The top-left x coordinate of the area to search within.
|
||||
* @param {number} y - The top-left y coordinate of the area to search within.
|
||||
* @param {number} width - The width of the area to search within.
|
||||
* @param {number} height - The height of the area to search within.
|
||||
* @param {boolean} [dynamic=true] - Search for Dynamic Bodies (true) or Static Bodies (false)
|
||||
*
|
||||
* @return {(Phaser.Physics.Arcade.Body[]|Phaser.Physics.Arcade.StaticBody[])} An array of bodies that overlap with the given area.
|
||||
*/
|
||||
overlapRect: function (x, y, width, height, dynamic)
|
||||
{
|
||||
if (dynamic === undefined) { dynamic = true; }
|
||||
|
||||
var output = [];
|
||||
var world = this.world;
|
||||
|
||||
var minMax = world.treeMinMax;
|
||||
|
||||
minMax.minX = x;
|
||||
minMax.minY = y;
|
||||
minMax.maxX = x + width;
|
||||
minMax.maxY = y + height;
|
||||
|
||||
if (!dynamic)
|
||||
{
|
||||
output = world.staticTree.search(minMax);
|
||||
}
|
||||
else if (world.useTree)
|
||||
{
|
||||
output = world.tree.search(minMax);
|
||||
}
|
||||
else
|
||||
{
|
||||
var bodies = world.bodies;
|
||||
|
||||
var fakeBody =
|
||||
{
|
||||
position: {
|
||||
x: x,
|
||||
y: y
|
||||
},
|
||||
left: x,
|
||||
top: y,
|
||||
right: x + width,
|
||||
bottom: y + height,
|
||||
isCircle: false
|
||||
};
|
||||
|
||||
var intersects = world.intersects;
|
||||
|
||||
bodies.iterate(function (target)
|
||||
{
|
||||
if (intersects(target, fakeBody))
|
||||
{
|
||||
output.push(target);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
return output;
|
||||
},
|
||||
|
||||
/**
|
||||
* The Scene that owns this plugin is shutting down.
|
||||
* We need to kill and reset all internal properties as well as stop listening to Scene events.
|
||||
|
|
Loading…
Reference in a new issue