Skip to content
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

Add z-index property support for tile layer #255

Closed
JumpLink opened this issue Nov 3, 2021 · 3 comments
Closed

Add z-index property support for tile layer #255

JumpLink opened this issue Nov 3, 2021 · 3 comments

Comments

@JumpLink
Copy link
Contributor

JumpLink commented Nov 3, 2021

Context

It is uncomfortable to have to use tile objects every time you want a tile to appear above the hero, for example rooftops, trees, etc. There should be an easier way to set whole layer above the hero. This is also a common approach, for example in RPG Maker.

Proposal

Add support for the ZIndex property as it is already available for Tile Objects.

@eonarheim
Copy link
Member

@JumpLink I agree, z index support per layer would be great.

Does this rely on a custom property for the layer? Something like this?

image

@eonarheim
Copy link
Member

eonarheim commented Nov 4, 2021

I'm 100% behind the z-indexed layers.

I propose we take a slightly different approach. Currently the Tiled plugin only creates one excalibur TileMap for all layers, it might make sense to create a TileMap for each layer instead.

Creating an Actor for each z-index'd tiled layer tile instance might cause some performance overhead they come with a lot of extra features. TileMap is a more efficient data structure for drawing tiles than actors.

TileMap currently supports z-indexing for the whole map. Z-indexes could be assigned to each TileMap based on the Tiled editor order which would keep them consistent with what the game designer/level editor sees.

const tilemap = new ex.TileMap(...);
const tx = tilemap.get(ex.TransformComponent);
tx.z = 5;

Perhaps we could add an optionally configurable base z-index that increments with the Tiled layers? Maybe another optional constructor argument?

const options = { 
   layerZIndexBase: 0
}
// Options are optional
const tiledResource = new TiledMapResource("/assets/map.tmx", options);
// or
const tiledResource = new TiledMapResource("/assets/map.tmx");

To implement z-indexed layers:

  1. Update the parsing logic to create TileMap per Tiled editor layer and store the list of TileMaps with the right z
  2. Smallish breaking change: Update getTileMap method accordingly to return the list of maps
  3. Update the addTiledMapToScene to add each TileMap to the Scene

@JumpLink
Copy link
Contributor Author

JumpLink commented Nov 4, 2021

@eonarheim sounds good. I'll see if I find the time to implement it that way.

To your screenshot: Yes, I would suggest that too.

What do you think of merging layers with the same zindex (or none) as is currently the case? Then we would still have the performance advantage as currently.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging a pull request may close this issue.

2 participants