Rendering TileMap in Pure Java

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: image
Here is my rendering: image

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 doesn’t seem to be working… I added the objectalignment and set it to topleft but there doesn’t seem to be any differences.

By the way, the MapObjects I am trying to render are Templates in Tiled. I don’t know if that’ll help anything.

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.4" tiledversion="1.4.2" orientation="orthogonal" renderorder="right-down" width="48" height="60" tilewidth="16" tileheight="16" infinite="0" nextlayerid="7" nextobjectid="41">
 <tileset firstgid="1" source="lavacaves.tsx" objectalignment="topleft"/>
 <tileset firstgid="257" source="../objects/prefabs/Trigger.tsx" objectalignment="topleft"/>
 <layer id="1" name="Tile Layer 1" width="48" height="60">

<!-- More stuff below -->

(Screenshot - Tiled Editor)

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…).