Simple-Tiled-Implementation
Simple-Tiled-Implementation copied to clipboard
Object positions aren't correct for isometric maps.
Describe the bug As the title says, the position of the objects aren't correct.
To Reproduce Steps to reproduce the behavior:
- Create a 16x16 isometric map in Tiled, with tiles that measure 30*24px (w * h)
- Add an object point on the bottom centermost tile (15, 15), set it's name to "Test Object"
- Add a custom layer in your code,
- Set the draw function to draw a sprite that's 30 * 36px (w * h)
- See that it works on pixel coords (225, 225) from the exported lua from Tiled.
- Change the coords of the object point in Tiled to (135, 135).
- Export and run again.
- See that it doesn't line up properly.
** Example Code **
local layer = map:addCustomLayer("Layer", 3)
local obj
for k, object in pairs(map.objects) do
if object.name == "Test Object" then
obj = object
break
end
end
layer.obj = {
sprite = love.graphics.newImage("sprite.png")
x = obj.y,
y = obj.x,
ox = 0,
oy = 0,
}
function layer:draw ()
love.graphics.draw(
self.obj.sprite,
self.obj.x,
self.obj.y,
0,
1,
1,
self.obj.ox,
self.obj.oy
)
end
Expected behavior I expect the object to line up properly in the tile coords.
Screenshots
Tiled:
Game:
Version
STI 1.2.3.0
After some more expermientation, I've concluded that it doesn't matter what size the object sprite is.
I've also found a rather strange issue, where one of the object points lines up properly, but the other doesn't.
Game:
Tiled
After even more testing, the positions of the rendering are correct in relation to the pixel coordinates exported from Tiled, but only in ortographic, and only if there's no scaling of the Map:draw
function.
Some Tiled objects act a little funny in that when you place them, their location is static and if you move any of their vertices, those vertices get offset values. So even if you move all the vertices of an object to a far off place, the object's "location" remains where it was initialized. Could this be the issue you're seeing?
Landon Manning [email protected]
On Mon, 14 Sep 2020 at 03:27, Mackan [email protected] wrote:
After even more testing, the positions of the rendering are correct in relation to the pixel coordinates exported from Tiled, but only in ortographic, and only if there's no scaling of the Map:draw function.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/karai17/Simple-Tiled-Implementation/issues/242#issuecomment-691842625, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEQD7APJXE5M3RKSFJKWHLSFWZWBANCNFSM4RKRFYIQ .
I'm not entirely sure, as it seems the objects are using the ortographic coordinates exported from Tiled, but aren't being converted into isometric coords properly.
As can be seen in the screenshots below, the green tiles aren't put at the right positions in regards to the rest of the map, but are rendered in screen space.
The (n, n)
prints are the x and y coords set on the object from STI.
Game:
Tiled:
After some help from @bjorn in the Tiled Discord, I've managed to get a workaround going;
function convertScreenToTile (x, y, tileHeight)
local xTile = math.ceil(x / tileHeight) - 2
local yTile = math.ceil(y / tileHeight) - 1
return xTile, yTile
end
local tileX, tileY = convertScreenToTile(object.x, object.y, map.tileheight)
local xPos, yPos = map:convertTileToPixel(tileX, tileY, map.tileheight)
The proposed solution by @Sven65 does not work for me. The object is still drawn outside the corresponding object layer. Also the convertTileToPixel does not accept that third argument as per sti init.lua file . Any suggestions ?
can you share your code and map files?