mirror of
https://github.com/photonstorm/phaser
synced 2024-11-26 14:40:38 +00:00
Fixed closest and furthest when the RTree is disabled
This commit is contained in:
parent
d36ada0386
commit
8e872fcb51
3 changed files with 37 additions and 21 deletions
14
CHANGELOG.md
14
CHANGELOG.md
|
@ -2,11 +2,15 @@
|
|||
|
||||
## Version 3.17.0 - Ishikawa - in dev
|
||||
|
||||
### Arcade Physics New Features, Updates and Fixes
|
||||
### Arcade Physics
|
||||
|
||||
#### 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`.
|
||||
* The `Body.delta` values are now able to be read and acted upon during a Scene update, due to the new game step flow. This means you can now call `this.physics.collide` during a Scene `update` and it will work properly again. Fix #4370 (thanks @NokFrt)
|
||||
|
||||
#### Updates
|
||||
|
||||
* `Body.preUpdate` is a new method that is called only once per game step. It resets all collision status properties and syncs the Body with the parent Game Object.
|
||||
* `Body.update` has been rewritten to just perform one single physics step and no longer re-syncs with the Game Object. It can be called multiple times per game step, depending on the World FPS rate.
|
||||
* `Body.postUpdate` has been rewritten to make it more compact. It syncs the body data back to the parent Game Object and is only called once per game step now (previously it was called whenever the Body updated)
|
||||
|
@ -18,6 +22,12 @@
|
|||
* The internal method `TileCheckX` now has a new argument `isLayer` which controls if the set comes from a layer or an array.
|
||||
* The internal method `TileCheckY` now has a new argument `isLayer` which controls if the set comes from a layer or an array.
|
||||
|
||||
#### Bug Fixes
|
||||
|
||||
* The `Body.delta` values are now able to be read and acted upon during a Scene update, due to the new game step flow. This means you can now call `this.physics.collide` during a Scene `update` and it will work properly again. Fix #4370 (thanks @NokFrt)
|
||||
* `ArcadePhysics.furthest` now iterates the bodies Set, rather than the RTree, which keeps it working even if the RTree has been disabled.
|
||||
* `ArcadePhysics.closest` now iterates the bodies Set, rather than the RTree, which keeps it working even if the RTree has been disabled.
|
||||
|
||||
### New Features
|
||||
|
||||
* There is a new Game Config property `input.windowEvents` which is true by default. It controls if Phaser will listen for any input events on the Window. If you disable this, Phaser will stop being able to emit events like `POINTER_UP_OUTSIDE`, or be aware of anything that happens outside of the Canvas re: input.
|
||||
|
|
|
@ -344,27 +344,29 @@ var ArcadePhysics = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* Finds the Body closest to a source point or object.
|
||||
* Finds the Dynamic Body closest to a source point or object.
|
||||
*
|
||||
* If two or more bodies are the exact same distance from the source point, only the first body
|
||||
* is returned.
|
||||
*
|
||||
* @method Phaser.Physics.Arcade.ArcadePhysics#closest
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {object} source - Any object with public `x` and `y` properties, such as a Game Object or Geometry object.
|
||||
* @param {any} source - Any object with public `x` and `y` properties, such as a Game Object or Geometry object.
|
||||
*
|
||||
* @return {Phaser.Physics.Arcade.Body} The closest Body to the given source point.
|
||||
* @return {Phaser.Physics.Arcade.Body} The closest Dynamic Body to the given source point.
|
||||
*/
|
||||
closest: function (source)
|
||||
{
|
||||
var bodies = this.world.tree.all();
|
||||
var bodies = this.world.bodies;
|
||||
|
||||
var min = Number.MAX_VALUE;
|
||||
var closest = null;
|
||||
var x = source.x;
|
||||
var y = source.y;
|
||||
|
||||
for (var i = bodies.length - 1; i >= 0; i--)
|
||||
bodies.iterate(function (target)
|
||||
{
|
||||
var target = bodies[i];
|
||||
var distance = DistanceSquared(x, y, target.x, target.y);
|
||||
|
||||
if (distance < min)
|
||||
|
@ -372,33 +374,36 @@ var ArcadePhysics = new Class({
|
|||
closest = target;
|
||||
min = distance;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return closest;
|
||||
},
|
||||
|
||||
/**
|
||||
* Finds the Body farthest from a source point or object.
|
||||
* Finds the Dynamic Body farthest from a source point or object.
|
||||
*
|
||||
* If two or more bodies are the exact same distance from the source point, only the first body
|
||||
* is returned.
|
||||
*
|
||||
* @method Phaser.Physics.Arcade.ArcadePhysics#furthest
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {object} source - Any object with public `x` and `y` properties, such as a Game Object or Geometry object.
|
||||
* @param {any} source - Any object with public `x` and `y` properties, such as a Game Object or Geometry object.
|
||||
*
|
||||
* @return {Phaser.Physics.Arcade.Body} The Body furthest from the given source point.
|
||||
* @return {Phaser.Physics.Arcade.Body} The Dynamic Body furthest away from the given source point.
|
||||
*/
|
||||
furthest: function (source)
|
||||
{
|
||||
var bodies = this.world.tree.all();
|
||||
var bodies = this.world.bodies;
|
||||
|
||||
var max = -1;
|
||||
var farthest = null;
|
||||
var x = source.x;
|
||||
var y = source.y;
|
||||
|
||||
for (var i = bodies.length - 1; i >= 0; i--)
|
||||
bodies.iterate(function (target)
|
||||
{
|
||||
var target = bodies[i];
|
||||
var distance = DistanceSquared(x, y, target.x, target.y);
|
||||
|
||||
if (distance > max)
|
||||
|
@ -406,7 +411,8 @@ var ArcadePhysics = new Class({
|
|||
farthest = target;
|
||||
max = distance;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return farthest;
|
||||
},
|
||||
|
|
|
@ -315,18 +315,19 @@ var World = new Class({
|
|||
this.maxEntries = GetValue(config, 'maxEntries', 16);
|
||||
|
||||
/**
|
||||
* Should this Arcade Physics World use an RTree for Dynamic Physics bodies or not?
|
||||
* Should this Arcade Physics World use an RTree for Dynamic and Static Physics bodies?
|
||||
*
|
||||
* An RTree is a fast way of spatially sorting of all the moving bodies in the world.
|
||||
* An RTree is a fast way of spatially sorting of all the bodies in the world.
|
||||
* However, at certain limits, the cost of clearing and inserting the bodies into the
|
||||
* tree every frame becomes more expensive than the search speed gains it provides.
|
||||
*
|
||||
* If you have a large number of dynamic bodies in your world then it may be best to
|
||||
* disable the use of the RTree by setting this property to `true`.
|
||||
* disable the use of the RTree by setting this property to `false` in the physics config.
|
||||
*
|
||||
* The number it can cope with depends on browser and device, but a conservative estimate
|
||||
* of around 5,000 bodies should be considered the max before disabling it.
|
||||
*
|
||||
* Note this only applies to dynamic bodies. Static bodies are always kept in an RTree,
|
||||
* This only applies to dynamic bodies. Static bodies are always kept in an RTree,
|
||||
* because they don't have to be cleared every frame, so you benefit from the
|
||||
* massive search speeds all the time.
|
||||
*
|
||||
|
@ -2301,7 +2302,6 @@ var World = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Wrap each object's coordinates within {@link Phaser.Physics.Arcade.World#bounds}.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue