Jump to content

depth sorting of entities from layer from tiled


aylictal
 Share

Recommended Posts

Hello again-

 

I'm looking for an efficient way to render top down view based upon json data from entities.  I have it working, as well as working with multiple layers, but now comes the difficult part.

Say I have a call such as:
 

this.map = this.make.tilemap({key: 'map'});
this.tileset = this.map.addTilesetImage('backgroundtiles');
this.layer = this.map.createStaticLayer('Tile Layer 1', this.tileset, 0, 0);
this.layer2 = this.map.createStaticLayer('Tile Layer 2', this.tileset, 0, 0);

This works, and it works beautifully. It renders the different layers and places them all effectively in the background.

Now the problem is that layer2 is a layer of trees, with varying individual tiles composing them (some are 4 tiles high, some are 3 tiles high, etc).

The player then runs around the map but the trees are always displaying behind him in render order, which is fine if the player is below (y position is greater than the y position of the respective tree). What I need the engine to do though is to render the tree in front of the player if the players y position is less than the y position of the tree, but I have no idea if it's even possible to get the actual tree y position.

Is there any efficient way to render the trees in front of the player if the players y position is less than the respective tree in consideration?  What is a good way to approach this problem when I desperately don't want to programmatically create the trees, but use the tree data from the json from Tiled?  Is this possible?

Thanks again, you guys rock!

Link to comment
Share on other sites

Hey @aylictal

Dynamic Tile Layer is basically static layer with more features (like tint/alpha of individual sprites)

https://photonstorm.github.io/phaser3-docs/Phaser.Tilemaps.DynamicTilemapLayer.html

It seems like there's currently no support for this feature (dynamic tile depth) so sprites seems to be the only way right now. Hopefully it will be added in the future.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...