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

Tiled layer order should help decide zIndex #285

Closed
luttje opened this issue Jan 8, 2022 · 3 comments · Fixed by #290
Closed

Tiled layer order should help decide zIndex #285

luttje opened this issue Jan 8, 2022 · 3 comments · Fixed by #290

Comments

@luttje
Copy link

luttje commented Jan 8, 2022

Right now the plugin needs us to specify a zindex property for individual inserted objects (and colliders). Tiled already provides it's own sorting system for layers. These layers are saved in order to a .tmx or .json file.

Steps to Reproduce

  1. Create a map in tiled with at least 2 tile layers and one or more object layers. (at least 2, because tile layers start at z index -1)
  2. Sort the layers so the objects are above the tile layers
  3. Create an inserted object (or collider) in one of the top object layers.
    For demonstration purposes I've positioned a fire (child of AnimatedFire layer) on top of the fireplace (child of Overlay1 layer):
    image
  4. Load the map in the way described in the README

Expected Result

I would expect the Tiled layer sorting to help this plugin decide the z index for the actors. Currently for tiles a z index is automatically decided, but this is not the actual order as the layer occurs in the map file. For actors and colliders an absolute zindex (specified in the property of the object) is needed.

Actual Result

The z index of the actor is unchanged (therefor 0) because no property is set. This causes the tiles to overlap the actor. (The tiles have their z index automatically decided starting from -1)
image

Current Workaround

Manually set a zindex property on each object and tile layers (this is how the examples in ./examples avoid this problem)

Proposed fix

Sadly I'm not motivated enough to create a PR, though I hope I can still aid you with a (hopefully) clear bug report and proposed fix:

  • The .tmx file contains all tile and object layers in order
  • This code would require a substantial change
  • The map file would have to be parsed preserving the order of the nodes
  • The layer's default zIndex would be it's offset from the first layer node

Should this be fixed?

In my opinion: eventually yes. Because:

  • The sorting is respected by the Tiled map editor.
  • The behavior intuitive.
  • When I didn't see my objects in-game it took me a good couple minutes to realize that it was not something I was doing wrong.
  • With more objects comes more manual management of z indexes, which can be tedious

However looking at the amount of work that is required to fix this, the workaround seems a viable alternative for now.

I really hope this helps you all.

Thanks for your time and effort!

@eonarheim
Copy link
Member

100% agree, I would expect consistent z-index/sorting behavior between Tiled and the plugin.

I think you're on track with the proposed fix 👍

@eonarheim
Copy link
Member

I think I might also be able to squeeze this one into the next release as well 🤞

@luttje
Copy link
Author

luttje commented Jan 12, 2022

Whether it makes the release or not: thanks a lot for your efforts!

eonarheim added a commit that referenced this issue Jan 14, 2022
Closes #285

This PR implements implicit z-ordering based on the Tiled editor order. Z-index can still be overridden with a custom property if desired. The first layer will start at `-1` z-index (the previous default) and will increment based on the Tiled order.

Example of inserted tiles using the implicit z-index, no more custom property!
![implicit-z](https://user-images.githubusercontent.com/612071/149061200-6f0b9885-1982-4c5f-9626-740cc380991f.gif)

Small-ish breaking change that moves all the optional properties to an option bag in the constructor

```typescript

// New constructor
const map = new TiledMapResource('path/to/map.tmx', { firstLayerZIndex: -2 });

// Old constructor
const map = new TiledMapResource('path/to/map.tmx', undefined, -2);
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants