mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 12:43:26 +00:00
Use a cached vector to save constant allocation and fixed y culling limit
This commit is contained in:
parent
2e50061699
commit
39f74d2e95
1 changed files with 9 additions and 5 deletions
|
@ -4,6 +4,10 @@
|
|||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
var Vector2 = require('../../math/Vector2');
|
||||
|
||||
var point = new Vector2();
|
||||
|
||||
/**
|
||||
* Checks if the given tile coordinate is within the isometric layer bounds, or not.
|
||||
*
|
||||
|
@ -21,13 +25,13 @@ var CheckIsoBounds = function (tileX, tileY, layer, camera)
|
|||
{
|
||||
var tilemapLayer = layer.tilemapLayer;
|
||||
var cullDistances = tilemapLayer.isoCullDistances;
|
||||
var pos = tilemapLayer.tileToWorldXY(tileX,tileY,undefined,camera);
|
||||
var pos = tilemapLayer.tilemap.tileToWorldXY(tileX, tileY, point, camera, tilemapLayer);
|
||||
|
||||
// we always subtract 1/2 of the tile's height/width to make the culling distance start from the center of the tiles.
|
||||
return pos.x > camera.worldView.x + tilemapLayer.scaleX * layer.tileWidth * (- cullDistances.x - 1 / 2)
|
||||
&& pos.x < camera.worldView.right + tilemapLayer.scaleX * layer.tileWidth * (cullDistances.x - 1 / 2)
|
||||
&& pos.y > camera.worldView.y + tilemapLayer.scaleY * layer.tileHeight * (- cullDistances.y - 1 / 2)
|
||||
&& pos.y < camera.worldView.bottom + tilemapLayer.scaleY * layer.tileHeight * (cullDistances.y - 1 / 2);
|
||||
return pos.x > camera.worldView.x + tilemapLayer.scaleX * layer.tileWidth * (-cullDistances.x - 0.5)
|
||||
&& pos.x < camera.worldView.right + tilemapLayer.scaleX * layer.tileWidth * (cullDistances.x - 0.5)
|
||||
&& pos.y > camera.worldView.y + tilemapLayer.scaleY * layer.tileHeight * (-cullDistances.y - 1.0)
|
||||
&& pos.y < camera.worldView.bottom + tilemapLayer.scaleY * layer.tileHeight * (cullDistances.y - 0.5);
|
||||
};
|
||||
|
||||
module.exports = CheckIsoBounds;
|
||||
|
|
Loading…
Reference in a new issue