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

Image objects incorrect origin #2136

Closed
huwpascoe opened this issue Jun 8, 2019 · 7 comments
Closed

Image objects incorrect origin #2136

huwpascoe opened this issue Jun 8, 2019 · 7 comments

Comments

@huwpascoe
Copy link

Took an hour before I figured out it was tiled and not my sketchy matrix math. For some reason the object's Y origin is default flipped so that 0,0 is on the bottom left compared to everything else. There's no way to set object origins either, so it's quite a weird situation!

@bjorn
Copy link
Member

bjorn commented Jun 10, 2019

Yeah, I'm sorry about this inconsistency. It really made sense when I introduced the support for tile objects years ago since I thought they would be primarily used for placing sprites on top-down maps, in which case bottom-alignment is usually the way to go for rendering order reasons. It sort of makes sense for jump-n-runs as well. However, it turned out that the inconsistency with other object types leads to much confusion.

It gets worse with isometric maps btw, which uses bottom-center alignment for tile objects. So the alignment of objects depends both on the type of object as well as the type of map.

For now the best solution is to find a way to deal with this, either in your engine or your loader. Eventually I do plan to add support a setting for object origin, so then it can be made all consistent.

I'll close this issue since it's already known for a long time and covered by #91.

@bjorn bjorn closed this as completed Jun 10, 2019
@huwpascoe
Copy link
Author

Ah, I see. I know this isn't a very glamorous feature to focus on, but please would you consider putting this on the roadmap? Speaking from experience, something like this is only going to get more difficult to implement the longer it's put aside!

@bjorn
Copy link
Member

bjorn commented Jun 10, 2019

@huwpascoe Alright, let's consider where we could add this option. First let's summarize the current behavior:

  • The map origin is in the top-left and shape objects are always top-left aligned. On isometric maps the top-left ends up being top-center in both cases, but that can be expected so it's fine.

  • Tile objects are treated differently. Their origin is bottom-left for orthogonal maps and bottom-center for isometric maps. In addition, they are shifted by a "drawing offset" specified on the tileset level. Note that not only are tile-objects bottom-left aligned, but so are the tiles on a tile layer, so in a way this is consistent (except that tiles on an isometric map are also bottom-left aligned and not bottom-center like tile objects on isometric maps).

I don't actually see a reason to make the map or shape object origins configurable. If it would become configurable, it probably makes sense to do this on the map level and have it affect both the map origin and shape object origins. This would enable support for inverting the Y axis properly (see also #2040), which is the only related feature people have been asking for.

For tiles and tile objects, an alignment setting could be introduced either on the tileset, the layer or the map (or on the tile, but I think that's covered by individual tile origin offsets (#871)). Of these, I think doing it on the tileset makes the most sense. There are generally less tilesets than layers / maps, so it's most comfortable projects that align all their tile objects the same way. In addition, there is probably more use-case for choosing a different alignment per tileset than doing this per layer / map. Finally, it kind of belongs together with the drawing offset that is already specified on the tileset level.

Now one question is, should this tileset alignment option affect only tile objects, or also tiles on tile layers? I guess it should, and it would make it easier to use tilesets like the "perspective_walls.png" example since it's more natural to change the alignment than setting a specific drawing offset. Note that it would not only change the tile origin, but also the anchor within each cell.

And then the default would likely remain orientation-specific for backwards compatibility reasons, while explicitly setting the tile alignment would make it consistent. Finally, setting the alignment to top-left would make it consistent with shape objects (though, that behavior is rarely useful for tile layers, so I'm not sure if we could eventually change to setting top-left as the default for new tilesets).

Deciding on the behavior is half the work. Opinions welcome!

@huwpascoe
Copy link
Author

I think it would be most useful to have origin attribute(s) per <tile> as in #871

This sprite with the origin marked in yellow for example.
image

The main requirements are:

  • tmx: If defined, <object> should provide absolute coordinates based on that origin, the item positioned top-left(0,0) would result in coord(8,8). Likewise, rotated 180, or flipped, still based on the top-left(0,0) would result in coord(24,8)

  • Editor: The object has to be able to rotate about the origin without changing the absolute coordinates. Positioned top-left(0,0), with origin-based coord(8,8). Using the rotate tool about 180 degrees would result in top-left(-16,0) and and coord(8,8)

@igroglaz
Copy link

igroglaz commented Jun 16, 2019

Funny, that I came on this topic when just googled around - I'm struggling with inverted 'y' too right now :D Got to rearrange all my locations inside out :E

Considering decision - fixing it @ map level would do the trick ;) And it's 100% alright if it would be hidden optional thing (in 'preferences' ui).

@bjorn
Copy link
Member

bjorn commented Jun 19, 2019

  • Likewise, rotated 180, or flipped, still based on the top-left(0,0) would result in coord(24,8)

@huwpascoe Note that tile object flipping really only applies to the image, so it would not change the visual position like rotation would. Unless we say that the origin is also affected by the flipping of the image. This probably would make sense, I just hope we're not making things too complicated.

As for the editor to be able to rotate without changing object position, currently the only way to do that is to change the rotation property in the Properties view. The object selection tool doesn't have an appropriate handle for rotating the object without changing its position (should probably be added, but it's not trivial since we don't want to make a big mess of handles either).

Considering decision - fixing it @ map level would do the trick ;) And it's 100% alright if it would be hidden optional thing (in 'preferences' ui).

@igroglaz Like I said in my comment above the tile alignment could be saved on map, layer or tileset level. I personally thought tileset would be a good fit. Do you have reasons to prefer it on a map level?

@igroglaz
Copy link

Oh, I see, I misunderstood it then :) Of course, tileset would be alright! 👍 Can't wait for this update!

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

No branches or pull requests

3 participants