Skip to content

Commit 39f74d2

Browse files
committed
Use a cached vector to save constant allocation and fixed y culling limit
1 parent 2e50061 commit 39f74d2

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/tilemaps/components/CheckIsoBounds.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
* @license {@link https://opensource.org/licenses/MIT|MIT License}
55
*/
66

7+
var Vector2 = require('../../math/Vector2');
8+
9+
var point = new Vector2();
10+
711
/**
812
* Checks if the given tile coordinate is within the isometric layer bounds, or not.
913
*
@@ -21,13 +25,13 @@ var CheckIsoBounds = function (tileX, tileY, layer, camera)
2125
{
2226
var tilemapLayer = layer.tilemapLayer;
2327
var cullDistances = tilemapLayer.isoCullDistances;
24-
var pos = tilemapLayer.tileToWorldXY(tileX,tileY,undefined,camera);
28+
var pos = tilemapLayer.tilemap.tileToWorldXY(tileX, tileY, point, camera, tilemapLayer);
2529

2630
// we always subtract 1/2 of the tile's height/width to make the culling distance start from the center of the tiles.
27-
return pos.x > camera.worldView.x + tilemapLayer.scaleX * layer.tileWidth * (- cullDistances.x - 1 / 2)
28-
&& pos.x < camera.worldView.right + tilemapLayer.scaleX * layer.tileWidth * (cullDistances.x - 1 / 2)
29-
&& pos.y > camera.worldView.y + tilemapLayer.scaleY * layer.tileHeight * (- cullDistances.y - 1 / 2)
30-
&& pos.y < camera.worldView.bottom + tilemapLayer.scaleY * layer.tileHeight * (cullDistances.y - 1 / 2);
31+
return pos.x > camera.worldView.x + tilemapLayer.scaleX * layer.tileWidth * (-cullDistances.x - 0.5)
32+
&& pos.x < camera.worldView.right + tilemapLayer.scaleX * layer.tileWidth * (cullDistances.x - 0.5)
33+
&& pos.y > camera.worldView.y + tilemapLayer.scaleY * layer.tileHeight * (-cullDistances.y - 1.0)
34+
&& pos.y < camera.worldView.bottom + tilemapLayer.scaleY * layer.tileHeight * (cullDistances.y - 0.5);
3135
};
3236

3337
module.exports = CheckIsoBounds;

0 commit comments

Comments
 (0)