Skip to content

Commit f8b3fcf

Browse files
committed
Cull Tiles now needs a render order for the layer data.
1 parent 838cdfc commit f8b3fcf

1 file changed

Lines changed: 75 additions & 9 deletions

File tree

src/tilemaps/components/CullTiles.js

Lines changed: 75 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ var SnapFloor = require('../../math/snap/SnapFloor');
88
var SnapCeil = require('../../math/snap/SnapCeil');
99

1010
/**
11-
* Returns the tiles in the given layer that are within the camera's viewport. This is used
12-
* internally.
11+
* Returns the tiles in the given layer that are within the camera's viewport. This is used internally.
1312
*
1413
* @function Phaser.Tilemaps.Components.CullTiles
1514
* @private
@@ -21,9 +20,10 @@ var SnapCeil = require('../../math/snap/SnapCeil');
2120
*
2221
* @return {Phaser.Tilemaps.Tile[]} An array of Tile objects.
2322
*/
24-
var CullTiles = function (layer, camera, outputArray)
23+
var CullTiles = function (layer, camera, outputArray, renderOrder)
2524
{
2625
if (outputArray === undefined) { outputArray = []; }
26+
if (renderOrder === undefined) { renderOrder = 0; }
2727

2828
outputArray.length = 0;
2929

@@ -61,21 +61,87 @@ var CullTiles = function (layer, camera, outputArray)
6161
drawBottom = Math.min(mapHeight, boundsBottom);
6262
}
6363

64-
for (var y = drawTop; y < drawBottom; y++)
64+
var x;
65+
var y;
66+
var tile;
67+
68+
if (renderOrder === 0)
6569
{
66-
for (var x = drawLeft; x < drawRight; x++)
70+
// right-down
71+
72+
for (y = drawTop; y < drawBottom; y++)
6773
{
68-
var tile = mapData[y][x];
74+
for (x = drawLeft; x < drawRight; x++)
75+
{
76+
tile = mapData[y][x];
77+
78+
if (!tile || tile.index === -1 || !tile.visible || tile.alpha === 0)
79+
{
80+
continue;
81+
}
82+
83+
outputArray.push(tile);
84+
}
85+
}
86+
}
87+
else if (renderOrder === 1)
88+
{
89+
// left-down
6990

70-
if (!tile || tile.index === -1 || !tile.visible || tile.alpha === 0)
91+
for (y = drawTop; y < drawBottom; y++)
92+
{
93+
for (x = drawRight; x >= drawLeft; x--)
7194
{
72-
continue;
95+
tile = mapData[y][x];
96+
97+
if (!tile || tile.index === -1 || !tile.visible || tile.alpha === 0)
98+
{
99+
continue;
100+
}
101+
102+
outputArray.push(tile);
73103
}
104+
}
105+
}
106+
else if (renderOrder === 2)
107+
{
108+
// right-up
74109

75-
outputArray.push(tile);
110+
for (y = drawBottom; y >= drawTop; y--)
111+
{
112+
for (x = drawLeft; x < drawRight; x++)
113+
{
114+
tile = mapData[y][x];
115+
116+
if (!tile || tile.index === -1 || !tile.visible || tile.alpha === 0)
117+
{
118+
continue;
119+
}
120+
121+
outputArray.push(tile);
122+
}
76123
}
77124
}
125+
else if (renderOrder === 3)
126+
{
127+
// left-up
128+
129+
for (y = drawBottom; y >= drawTop; y--)
130+
{
131+
for (x = drawRight; x >= drawLeft; x--)
132+
{
133+
tile = mapData[y][x];
78134

135+
if (!tile || tile.index === -1 || !tile.visible || tile.alpha === 0)
136+
{
137+
continue;
138+
}
139+
140+
outputArray.push(tile);
141+
}
142+
}
143+
}
144+
79145
tilemapLayer.tilesDrawn = outputArray.length;
80146
tilemapLayer.tilesTotal = mapWidth * mapHeight;
81147

0 commit comments

Comments
 (0)