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

BaseTmxMapLoader ignores rotation for Objects #6180

Closed
6 tasks done
deveth0 opened this issue Sep 9, 2020 · 7 comments
Closed
6 tasks done

BaseTmxMapLoader ignores rotation for Objects #6180

deveth0 opened this issue Sep 9, 2020 · 7 comments
Assignees
Labels

Comments

@deveth0
Copy link

deveth0 commented Sep 9, 2020

Please ensure you have given all the following requested information in your report.

Issue details

The BaseTmxMapLoader is supports loading of map objects since #3751. I'm not 100% sure, if this is a bug, but I feel like that.

When setting the rotation on a map object in Tiled Map Editor, it is only add as property to the final MapObject (e.g. Polygon or Rectangle) but the object is not really rotated.

https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/maps/tiled/BaseTmxMapLoader.java#L383

Reproduction steps/code

You can find a simple demo of the problem here:
https://github.com/deveth0/libgdx_tiledMapObjectRotationDemo

Basically I added some Tile where the left side of the tile is covered by a Rectangle which is rotated by 90°.

expected
expected_props

For simplicity i used a Rectangle here, but this is also an issue for Polygons. Only TiledMapTileMapObject seem to be rotated correct (https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/maps/tiled/BaseTmxMapLoader.java#L376)

Version of LibGDX and/or relevant dependencies

gdxVersion = '1.9.11'

Please select the affected platforms

  • Android
  • iOS (robovm)
  • HTML/GWT
  • Windows
  • Linux
  • MacOS
@mgsx-dev mgsx-dev self-assigned this Sep 9, 2020
@mgsx-dev
Copy link
Contributor

mgsx-dev commented Sep 9, 2020

@deveth0 the thing is rotation can be arbitrary (other than 90° angle) and some underlying shapes (Rectangle and Ellipse) doesn't have rotation conceptually.

TiledMapTileMapObject holds a rotation field for convenience but the underlying "shape" (texture region) doesn't have rotation for the same reason.

About Polygon and Polyline, shapes could be rotated directly but it would break consistency with other shapes.

I understand it's not a perfect design but i think it's user code responsibility to apply rotation to their final game object (TiledMapTileMapObject is typically a Sprite, RectangleMapObject could be a box2D body, and so on).

If you're OK with that, you can close the issue.

@deveth0
Copy link
Author

deveth0 commented Sep 9, 2020

@mgsx-dev thank you for your fast reply although i disagree with ya ;)

I mean, the sole reason for the TmxMapLoader is to get a predefined Map into libgdx with as much information as possible. Imho this also includes the rotation of objects as this is as important as e.g. their positioning.
So the current implementation seems to be quite inconsistent.

Given that there are only RectangleMapObject and EllipseMapObject that don't support the rotation, why not use a fake rotation by modifying their bounds? In the end you won't care if the rectangle is still 32x16 px or 16x32 px i guess...

@mgsx-dev
Copy link
Contributor

mgsx-dev commented Sep 9, 2020

@deveth0 actually all MapObjects do have the rotation information. You can get this information via Properties and use it in your game, eg. you can use it for a sprite, for a Box2D body, a custom Object or whatever usage for your game.

@deveth0
Copy link
Author

deveth0 commented Sep 9, 2020

yeah, that's what I need to do right now. But with the same argument you could remove the x and y property ;)

I fully understand your reasoning, it's just quite inconsistent that some objects are rotated (TiledMapTileMapObject) and others arent.

@mgsx-dev
Copy link
Contributor

mgsx-dev commented Sep 9, 2020

Actually TiledMapTileMapObject is not rotated, it hold the rotation via properties (and as an attribute for convenience), user code may use it (eg. with a sprite or something else) but the underlying "shape" (texture region) doesn't have rotation. So it sounds consistent to me.
I'll let maintainers state on this issue.

@deveth0
Copy link
Author

deveth0 commented Sep 9, 2020

thanks :) Even if this is not "fixed", I'm glad for the explaination!

@mgsx-dev
Copy link
Contributor

I guess there is no further debate, i'm closing.

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

No branches or pull requests

3 participants