From 39f74d2e953c9f4dc8068e77d123f1109885ca58 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Sun, 11 Oct 2020 23:03:52 +0100 Subject: [PATCH] Use a cached vector to save constant allocation and fixed y culling limit --- src/tilemaps/components/CheckIsoBounds.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/tilemaps/components/CheckIsoBounds.js b/src/tilemaps/components/CheckIsoBounds.js index 71987aaa4..c09344318 100644 --- a/src/tilemaps/components/CheckIsoBounds.js +++ b/src/tilemaps/components/CheckIsoBounds.js @@ -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;