Skip to content

Commit ab753ff

Browse files
committed
Tilemaps.Components.StaggeredCullTiles is a new function that culls tiles in a staggered map.
1 parent 0b8b9fb commit ab753ff

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2020 Photon Storm Ltd.
4+
* @license {@link https://opensource.org/licenses/MIT|MIT License}
5+
*/
6+
7+
var CullBounds = require('./StaggeredCullBounds');
8+
var RunCull = require('./RunCull');
9+
10+
/**
11+
* Returns the tiles in the given layer that are within the cameras viewport. This is used internally.
12+
*
13+
* @function Phaser.Tilemaps.Components.StaggeredCullTiles
14+
* @since 3.50.0
15+
*
16+
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
17+
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera to run the cull check against.
18+
* @param {array} [outputArray] - An optional array to store the Tile objects within.
19+
* @param {integer} [renderOrder=0] - The rendering order constant.
20+
*
21+
* @return {Phaser.Tilemaps.Tile[]} An array of Tile objects.
22+
*/
23+
var StaggeredCullTiles = function (layer, camera, outputArray, renderOrder)
24+
{
25+
if (outputArray === undefined) { outputArray = []; }
26+
if (renderOrder === undefined) { renderOrder = 0; }
27+
28+
outputArray.length = 0;
29+
30+
var tilemapLayer = layer.tilemapLayer;
31+
32+
if (!tilemapLayer.skipCull && tilemapLayer.scrollFactorX === 1 && tilemapLayer.scrollFactorY === 1)
33+
{
34+
// Camera world view bounds, snapped for scaled tile size
35+
// Cull Padding values are given in tiles, not pixels
36+
37+
var bounds = CullBounds(layer, camera);
38+
39+
RunCull(layer, bounds, renderOrder, outputArray);
40+
}
41+
42+
return outputArray;
43+
};
44+
45+
module.exports = StaggeredCullTiles;

0 commit comments

Comments
 (0)