Skip to content

Commit cc5bf41

Browse files
committed
Added renderOrder property and setRenderOrder method.
1 parent b0888d2 commit cc5bf41

1 file changed

Lines changed: 66 additions & 1 deletion

File tree

src/tilemaps/dynamiclayer/DynamicTilemapLayer.js

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,29 @@ var DynamicTilemapLayer = new Class({
207207
*/
208208
this.cullCallback = TilemapComponents.CullTiles;
209209

210+
/**
211+
* The rendering (draw) order of the tiles in this layer.
212+
*
213+
* The default is 0 which is 'right-down', meaning it will draw the tiles starting from the top-left,
214+
* drawing to the right and then moving down to the next row.
215+
*
216+
* The draw orders are:
217+
*
218+
* 0 = right-down
219+
* 1 = left-down
220+
* 2 = right-up
221+
* 3 = left-up
222+
*
223+
* This can be changed via the `setRenderOrder` method.
224+
*
225+
* @name Phaser.Tilemaps.DynamicTilemapLayer#_renderOrder
226+
* @type {integer}
227+
* @default 0
228+
* @private
229+
* @since 3.12.0
230+
*/
231+
this._renderOrder = 0;
232+
210233
this.setAlpha(this.layer.alpha);
211234
this.setPosition(x, y);
212235
this.setOrigin();
@@ -215,6 +238,48 @@ var DynamicTilemapLayer = new Class({
215238
this.initPipeline('TextureTintPipeline');
216239
},
217240

241+
/**
242+
* Sets the rendering (draw) order of the tiles in this layer.
243+
*
244+
* The default is 'right-down', meaning it will order the tiles starting from the top-left,
245+
* drawing to the right and then moving down to the next row.
246+
*
247+
* The draw orders are:
248+
*
249+
* 0 = right-down
250+
* 1 = left-down
251+
* 2 = right-up
252+
* 3 = left-up
253+
*
254+
* Setting the render order does not change the tiles or how they are stored in the layer,
255+
* it purely impacts the order in which they are rendered.
256+
*
257+
* You can provide either an integer (0 to 3), or the string version of the order.
258+
*
259+
* @method Phaser.Tilemaps.DynamicTilemapLayer#setRenderOrder
260+
* @since 3.12.0
261+
*
262+
* @param {(integer|string)} renderOrder - The render (draw) order value. Either an integer between 0 and 3, or a string: 'right-down', 'left-down', 'right-up' or 'left-up'.
263+
*
264+
* @return {this} This Tilemap Layer object.
265+
*/
266+
setRenderOrder: function (renderOrder)
267+
{
268+
var orders = [ 'right-down', 'left-down', 'right-up', 'left-up' ];
269+
270+
if (typeof renderOrder === 'string')
271+
{
272+
renderOrder = orders.indexOf(renderOrder);
273+
}
274+
275+
if (renderOrder >= 0 && renderOrder < 4)
276+
{
277+
this._renderOrder = renderOrder;
278+
}
279+
280+
return this;
281+
},
282+
218283
/**
219284
* Calculates interesting faces at the given tile coordinates of the specified layer. Interesting
220285
* faces are used internally for optimizing collisions against tiles. This method is mostly used
@@ -295,7 +360,7 @@ var DynamicTilemapLayer = new Class({
295360
*/
296361
cull: function (camera)
297362
{
298-
return this.cullCallback(this.layer, camera, this.culledTiles);
363+
return this.cullCallback(this.layer, camera, this.culledTiles, this._renderOrder);
299364
},
300365

301366
/**

0 commit comments

Comments
 (0)