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

fix tile layers y value #14

Closed
wants to merge 1 commit into from
Closed

Conversation

defaultxr
Copy link
Contributor

Tiled specifies an object's position by its bottom left point, relative to the top left of the map. So a 32x32 object at the top left of the map would be at position 0,32. Tiled's format doesn't specify the position of each tile in a tile layer, but cl-tiled's cell-y function still seems wrong to me, as calling cell-y on the top left tile returns 0 but calling object-y on an object positioned directly over it gives 32. This PR aligns cell-y and object-y.

@defaultxr
Copy link
Contributor Author

defaultxr commented Jan 12, 2019

It looks like there is an issue about this open in Tiled's bug tracker here: mapeditor/tiled#91 so I guess it is a known problem.

It seems better to me to fix this in the library rather than punting the complexity to users of the library (imo Lisp is supposed to be a reprieve from the "worse is better" design philosophy).

@Zulu-Inuoe
Copy link
Owner

I apologize for delays.
It took me a while to understand what the actual problem was, but now I see.
I'll describe it here as well as I can, for posterity:

  1. Create a map
  2. Add an object layer
  3. Using any tileset, create a 'Tile Object' on the object layer (shortcut key T)
  4. Set object X and Y to 0

The object will be placed one row above the rest of the tileset.
This doesn't seem to be the end of it, however. The whole way objects work seems to be a bit interesting. I'll describe what I've found:

  1. Rectangles and ellipses without width/height values use X/Y as their -center-.
  2. Rectangles and ellipses with their width/height values set use X/Y as their top-left corner
  3. Polygon objects use X/Y to position the first point in the polygon. Rotations rotate about this point
  4. Tile Objects use X/Y as the bottom-left corner
  5. Text Objects use X/Y as their top-left corner

These rules apply even for collision objects in the Tile Collision Editor.

Given that, I don't know that this is a good fix for the problem two important reasons:a few reasons:
Firstly, while it aligns the tiles and Tile Objects' positions, it then causes trouble for the positions of all the other object types. So in my mind, it breaks more than it fixes.
Secondly, the behaviour between the Tiled editor and cl-tiled would disagree, leading to the same map being rendered differently between the two.

I do agree with the sentiment of fixing it in the library so that each user doesn't have to fix it, but I don't want positioning to be different between the editor and this code.
My proposed fix would be to keep this code as-is and consider it the 'low level interface'. Then provide an interface that provides a simpler behaviour to make it easier for library users so they don't each have to encode these very specific rules in order to get a 1-to-1 with the Tiled editor.
More concretely, something like providing places for object-center, object-left, etc.

So what I'll do is I'll close this PR, open an issue and try and explain this and we can talk about it some.

Thanks for bringing this up!

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 this pull request may close these issues.

2 participants