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

Object positions aren't correct for isometric maps. #242

Open
Sven65 opened this issue Sep 13, 2020 · 8 comments
Open

Object positions aren't correct for isometric maps. #242

Sven65 opened this issue Sep 13, 2020 · 8 comments

Comments

@Sven65
Copy link

Sven65 commented Sep 13, 2020

Describe the bug
As the title says, the position of the objects aren't correct.

To Reproduce
Steps to reproduce the behavior:

  1. Create a 16x16 isometric map in Tiled, with tiles that measure 30*24px (w * h)
  2. Add an object point on the bottom centermost tile (15, 15), set it's name to "Test Object"
  3. Add a custom layer in your code,
  4. Set the draw function to draw a sprite that's 30 * 36px (w * h)
  5. See that it works on pixel coords (225, 225) from the exported lua from Tiled.
  6. Change the coords of the object point in Tiled to (135, 135).
  7. Export and run again.
  8. 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:
Tiled

Game:
Game

Version

STI 1.2.3.0

@Sven65
Copy link
Author

Sven65 commented Sep 13, 2020

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:
Game

Tiled
Tiled

@Sven65
Copy link
Author

Sven65 commented Sep 14, 2020

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.

@karai17
Copy link
Owner

karai17 commented Sep 15, 2020 via email

@Sven65
Copy link
Author

Sven65 commented Sep 15, 2020

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.

@Sven65
Copy link
Author

Sven65 commented Sep 16, 2020

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:
Game

Tiled:

Tiled

@Sven65
Copy link
Author

Sven65 commented Sep 16, 2020

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)

@JoaoSobral
Copy link

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 ?
Screenshot_20230209_001813

@karai17
Copy link
Owner

karai17 commented Feb 10, 2023

can you share your code and map files?

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