Hi, I’m creating a system to render a .tmx file in pure Java (no LibGDX, no external libraries, etc… I want to keep it this way, so please do not suggest a library as my solution).
Rendering the map works seamlessly, but when I go to render objects, they seem to be slightly misplaced along the Y axis.
Here is the editor:
Here is my rendering:
As you can see, the rocks are slightly misplaced and I think it is because of the corner from which Tiled renders the objects.
In my code, I render my MapObjects (the rocks), with their position in the .tmx file as the top left corner, whereas I think Tiled renders them from the bottom left corner. I have debugged my code thoroughly, and the positions of the MapObjects and the object positions in the .tmx file are identical, so that is not the issue.
Is there any way I can make it so they render from the same corner so my map objects show up where I want them regardless if I am using the editor or my code?
Tiled renders tiles and Tile Objects from the bottom left by default, you are correct.
Check the Object Alignment property in your tileset. You can set it to Top Left instead, to match the way you render things in your game. Or, you can choose to make the correction in your code instead. Doing it in Tiled is probably easier, since it simplifies your game code when handling things like rotations.
It seems like you’ve been hand-editing the TMX file and have added the objectalignment attribute to an external tileset reference. You need to add it on the tileset element in the lavacaves.tsx and Trigger.tsx files instead (or you could use Tiled to change this property, you can find it under Tileset > Tileset Properties…).