Skip to content

Add optional sortByY param to tilemap createFromObjects method #7183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: v4.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/tilemaps/Tilemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand Down
1 change: 1 addition & 0 deletions src/tilemaps/typedefs/CreateFromObjectLayerConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/