Skip to content

Commit 89db843

Browse files
committed
Added skipCull property and setSkipCull method
1 parent a8fa98e commit 89db843

2 files changed

Lines changed: 48 additions & 5 deletions

File tree

src/tilemaps/components/CullTiles.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var CullTiles = function (layer, camera, outputArray)
2828
outputArray.length = 0;
2929

3030
var tilemapLayer = layer.tilemapLayer;
31+
var skipCull = tilemapLayer.skipCull;
3132

3233
var tileW = Math.floor(layer.tileWidth * tilemapLayer.scaleX);
3334
var tileH = Math.floor(layer.tileHeight * tilemapLayer.scaleY);
@@ -51,18 +52,25 @@ var CullTiles = function (layer, camera, outputArray)
5152
{
5253
var tile = mapData[y][x];
5354

54-
if (!tile || tile.index === -1 || !tile.visible)
55+
if (!tile || tile.index === -1 || !tile.visible || tile.alpha === 0)
5556
{
5657
continue;
5758
}
5859

59-
var tilePixelX = (tile.pixelX + tilemapLayer.x) * tilemapLayer.scaleX;
60-
var tilePixelY = (tile.pixelY + tilemapLayer.y) * tilemapLayer.scaleY;
61-
62-
if (tilePixelX >= boundsLeft && tilePixelX + tileW <= boundsRight && tilePixelY >= boundsTop && tilePixelY + tileH <= boundsBottom)
60+
if (skipCull)
6361
{
6462
outputArray.push(tile);
6563
}
64+
else
65+
{
66+
var tilePixelX = (tile.pixelX + tilemapLayer.x) * tilemapLayer.scaleX;
67+
var tilePixelY = (tile.pixelY + tilemapLayer.y) * tilemapLayer.scaleY;
68+
69+
if (tilePixelX >= boundsLeft && tilePixelX + tileW <= boundsRight && tilePixelY >= boundsTop && tilePixelY + tileH <= boundsBottom)
70+
{
71+
outputArray.push(tile);
72+
}
73+
}
6674

6775
i++;
6876
}

src/tilemaps/dynamiclayer/DynamicTilemapLayer.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@ var DynamicTilemapLayer = new Class({
131131
*/
132132
this.culledTiles = [];
133133

134+
/**
135+
* You can control if the Cameras should cull tiles before rendering them or not.
136+
* By default the camera will try to cull the tiles in this layer, to avoid over-drawing to the renderer.
137+
*
138+
* However, there are some instances when you may wish to disable this, and toggling this flag allows
139+
* you to do so. Also see `setSkipCull` for a chainable method that does the same thing.
140+
*
141+
* @name Phaser.Tilemaps.DynamicTilemapLayer#skipCull
142+
* @type {boolean}
143+
* @since 3.11.0
144+
*/
145+
this.skipCull = false;
146+
134147
this.setAlpha(this.layer.alpha);
135148
this.setPosition(x, y);
136149
this.setOrigin();
@@ -742,6 +755,28 @@ var DynamicTilemapLayer = new Class({
742755
return this;
743756
},
744757

758+
/**
759+
* You can control if the Cameras should cull tiles before rendering them or not.
760+
* By default the camera will try to cull the tiles in this layer, to avoid over-drawing to the renderer.
761+
*
762+
* However, there are some instances when you may wish to disable this.
763+
*
764+
* @method Phaser.Tilemaps.DynamicTilemapLayer#setSkipCull
765+
* @since 3.11.0
766+
*
767+
* @param {boolean} [value=true] - Set to `true` to stop culling tiles. Set to `false` to enable culling again.
768+
*
769+
* @return {this} This Tilemap Layer object.
770+
*/
771+
setSkipCull: function (value)
772+
{
773+
if (value === undefined) { value = true; }
774+
775+
this.skipCull = value;
776+
777+
return this;
778+
},
779+
745780
/**
746781
* Sets collision on the given tile or tiles within a layer by index. You can pass in either a
747782
* single numeric index or an array of indexes: [2, 3, 15, 20]. The `collides` parameter controls if

0 commit comments

Comments
 (0)