Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Need help converting coordinates into tile_x/y in iso view
- By EdwinOdesseiron Date 2013-11-14 19:46
Hi all. I encountered a problem that I can't seem to get my head around to make it work.

I've made a few changes, and one of them was putting a game into isometric view. Some things work great, but I have a problem calculating player's tile_x and tile_y position on isometric grid.

The grid is drawn this way:
cx = x * 32 # x * tile_width/2
cy = y * 32 # y * tile_height
isoX = cx - cy
isoY = (cx + cy) / 2
@tileset[@tiles[l][y][x]].draw(isoX + @offset_x + @hud_offset, isoY + @offset_y, l)


And it works well. But I can't seem to get my head around putting players on correct positions. I tried with this code:
@x = (tile_x * 32) - (tile_y*32)
@y = ((tile_x * 32) + (tile_y * 32) / 2) - @sprite.height

While sending player characters to tiles: {4:3}, {3:4}, {4:2} and {2:3}, and according to prints, they are at correct positions, but when I displayed tile x and y, they seem to be a bit off (2-3 tiles).
And another problem is that I can't seem to correctly calculate @tile_x and @tile_y position of player when I have their @x and @y. When printing, I get this data:
Player 0 placed at 4:3
Updating
Player 0 at 2:3
===
Player 1 placed at 3:4
Updating
Player 1 at 1:3
===
Player 2 placed at 4:2
Updating
Player 2 at 2:2
===
Player 3 placed at 2:3
Updating
Player 3 at 0:2

with calculations:
@tile_x = ((@x / 32) + (@y / 32)) / 2
@tile_y = ((@y / 16) - (@x / 32)) / 2

Which, again, gives off different values. Anyone have any clues how to calculate @x and @y when passing tile_x and tile_x and vice versa, calculating @tile_x and @tile_y when passing x and y?

Dimensions of single tiles are 64x32, and player sprite is 64x64. Thanks in advance.
Up Topic Gosu / Gosu Exchange / Need help converting coordinates into tile_x/y in iso view

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill