phaser/src/tilemaps/components/CullTiles.js

50 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2022-02-28 14:29:51 +00:00
* @copyright 2022 Photon Storm Ltd.
2019-05-10 15:15:04 +00:00
* @license {@link https://opensource.org/licenses/MIT|MIT License}
2018-02-12 16:01:20 +00:00
*/
2020-10-02 12:47:36 +00:00
var CullBounds = require('./CullBounds');
var RunCull = require('./RunCull');
2020-09-19 08:56:05 +00:00
/**
2020-10-02 12:47:36 +00:00
* Returns the tiles in the given layer that are within the cameras viewport. This is used internally.
2020-09-19 08:56:05 +00:00
*
2020-10-02 12:47:36 +00:00
* @function Phaser.Tilemaps.Components.CullTiles
* @since 3.50.0
2018-02-08 01:08:59 +00:00
*
2018-02-08 02:02:37 +00:00
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
2020-10-02 12:47:36 +00:00
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera to run the cull check against.
* @param {array} [outputArray] - An optional array to store the Tile objects within.
2020-11-23 10:22:13 +00:00
* @param {number} [renderOrder=0] - The rendering order constant.
*
2018-02-08 02:02:37 +00:00
* @return {Phaser.Tilemaps.Tile[]} An array of Tile objects.
2017-11-26 15:05:19 +00:00
*/
2020-10-02 12:47:36 +00:00
var CullTiles = function (layer, camera, outputArray, renderOrder)
{
if (outputArray === undefined) { outputArray = []; }
if (renderOrder === undefined) { renderOrder = 0; }
outputArray.length = 0;
2018-07-15 01:09:36 +00:00
var tilemapLayer = layer.tilemapLayer;
2018-07-12 00:14:34 +00:00
2020-11-20 14:58:43 +00:00
// Camera world view bounds, snapped for scaled tile size
// Cull Padding values are given in tiles, not pixels
var bounds = CullBounds(layer, camera);
2020-09-19 08:56:05 +00:00
2020-11-20 14:58:43 +00:00
if (tilemapLayer.skipCull || tilemapLayer.scrollFactorX !== 1 || tilemapLayer.scrollFactorY !== 1)
{
bounds.left = 0;
bounds.right = layer.width;
bounds.top = 0;
bounds.bottom = layer.height;
}
2020-11-20 14:58:43 +00:00
RunCull(layer, bounds, renderOrder, outputArray);
return outputArray;
};
module.exports = CullTiles;