diff --git a/src/tilemaps/Tilemap.js b/src/tilemaps/Tilemap.js index 5969fadae1..0ffd5d7385 100644 --- a/src/tilemaps/Tilemap.js +++ b/src/tilemaps/Tilemap.js @@ -818,6 +818,11 @@ var Tilemap = new Class({ var objects = objectLayer.objects; + if (config.sortByY)) + { + objects.sort((a,b) => a.y > b.y ? 1 : -1) + } + for (var c = 0; c < config.length; c++) { var singleConfig = config[ c ]; diff --git a/src/tilemaps/typedefs/CreateFromObjectLayerConfig.js b/src/tilemaps/typedefs/CreateFromObjectLayerConfig.js index d48bf63df5..e70a310a26 100644 --- a/src/tilemaps/typedefs/CreateFromObjectLayerConfig.js +++ b/src/tilemaps/typedefs/CreateFromObjectLayerConfig.js @@ -12,4 +12,5 @@ * @property {Phaser.GameObjects.Container} [container] - Optional Container to which the Game Objects are added. * @property {(string|Phaser.Textures.Texture)} [key] - Optional key of a Texture to be used, as stored in the Texture Manager, or a Texture instance. If omitted, the object's gid's tileset key is used if available. * @property {(string|number)} [frame] - Optional name or index of the frame within the Texture. If omitted, the tileset index is used, assuming that spritesheet frames exactly match tileset indices & geometries -- if available. + * @property {boolean} [sortByY=false] - Sort objects in layer by their y position. Objects with a higher y are displayed above objects with a lower y. */