Skip to content

Commit 31421ee

Browse files
committed
The CullTiles updates from 3.11 didn't factor in the position of the Tilemap Layer to its bounds calculations, causing Static layers displayed out of the Camera viewport to never render in Canvas mode. The method has also been optimized further, with less divisions and less checks if culling is disabled.
1 parent 1b5f084 commit 31421ee

2 files changed

Lines changed: 16 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Setting the `resolution` property in the Game Config to a value other than 1 wou
109109
* The `CameraManager` was accidentally adding extra destroy event calls when a Scene was restarted, causing an `Uncaught TypeError: Cannot read property 'events' of null` when trying to destroy a game instance having swapped from a Scene to another, and back again. Fix #3878 (thanks @mbunby)
110110
* RenderTextures in WebGL will now set the viewport size, stopping the console warning in Firefox. Fix #3823 (thanks @SBCGames)
111111
* Particles now take the Cameras alpha value into consideration when calculating their final alpha values in WebGL. They previously ignored it. If you now alpha a Camera out all particles will change accordingly.
112+
* The `CullTiles` updates from 3.11 didn't factor in the position of the Tilemap Layer to its bounds calculations, causing Static layers displayed out of the Camera viewport to never render in Canvas mode. The method has also been optimized further, with less divisions and less checks if culling is disabled.
112113

113114
### Examples, Documentation and TypeScript
114115

src/tilemaps/components/CullTiles.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ var CullTiles = function (layer, camera, outputArray)
2727

2828
outputArray.length = 0;
2929

30-
var y = 0;
31-
var x = 0;
32-
var tile = null;
33-
3430
var tilemapLayer = layer.tilemapLayer;
3531

3632
var mapData = layer.data;
@@ -40,31 +36,32 @@ var CullTiles = function (layer, camera, outputArray)
4036
var tileW = Math.floor(layer.tileWidth * tilemapLayer.scaleX);
4137
var tileH = Math.floor(layer.tileHeight * tilemapLayer.scaleY);
4238

43-
// Camera world view bounds, snapped for scaled tile size
44-
45-
var boundsLeft = SnapFloor(camera.worldView.x, tileW) - (tilemapLayer.cullPaddingX * tileW);
46-
var boundsRight = SnapCeil(camera.worldView.right, tileW) + (tilemapLayer.cullPaddingX * tileW);
47-
var boundsTop = SnapFloor(camera.worldView.y, tileH) - (tilemapLayer.cullPaddingY * tileH);
48-
var boundsBottom = SnapCeil(camera.worldView.bottom, tileH) + (tilemapLayer.cullPaddingY * tileH);
49-
5039
var drawLeft = 0;
5140
var drawRight = mapWidth;
5241
var drawTop = 0;
5342
var drawBottom = mapHeight;
5443

5544
if (!tilemapLayer.skipCull)
5645
{
57-
drawLeft = Math.max(0, boundsLeft / tileW);
58-
drawRight = Math.min(mapWidth, boundsRight / tileW);
59-
drawTop = Math.max(0, boundsTop / tileH);
60-
drawBottom = Math.min(mapHeight, boundsBottom / tileH);
46+
// Camera world view bounds, snapped for scaled tile size
47+
// Cull Padding values are given in tiles, not pixels
48+
49+
var boundsLeft = SnapFloor(camera.worldView.x - tilemapLayer.x, tileW, 0, true) - tilemapLayer.cullPaddingX;
50+
var boundsRight = SnapCeil(camera.worldView.right - tilemapLayer.x, tileW, 0, true) + tilemapLayer.cullPaddingX;
51+
var boundsTop = SnapFloor(camera.worldView.y - tilemapLayer.y, tileH, 0, true) - tilemapLayer.cullPaddingY;
52+
var boundsBottom = SnapCeil(camera.worldView.bottom - tilemapLayer.y, tileH, 0, true) + tilemapLayer.cullPaddingY;
53+
54+
drawLeft = Math.max(0, boundsLeft);
55+
drawRight = Math.min(mapWidth, boundsRight);
56+
drawTop = Math.max(0, boundsTop);
57+
drawBottom = Math.min(mapHeight, boundsBottom);
6158
}
6259

63-
for (y = drawTop; y < drawBottom; y++)
60+
for (var y = drawTop; y < drawBottom; y++)
6461
{
65-
for (x = drawLeft; x < drawRight; x++)
62+
for (var x = drawLeft; x < drawRight; x++)
6663
{
67-
tile = mapData[y][x];
64+
var tile = mapData[y][x];
6865

6966
if (!tile || tile.index === -1 || !tile.visible || tile.alpha === 0)
7067
{

0 commit comments

Comments
 (0)