Isometric - precise screen coordinates to isometric
Posted
by
Rawrz
on Game Development
See other posts from Game Development
or by Rawrz
Published on 2012-12-11T08:44:58Z
Indexed on
2012/12/11
11:18 UTC
Read the original article
Hit count: 573
I'm trying to translate mouse coords to precise isometric coords (I can already find the tile the mouse is over, but I want it to be more precise). I've tried several different methods but I seem to keep falling short.
For drawing I use:
batch.draw(
texture,
(y * tileWidth / 2) + (x * tileWidth / 2),
(x * tileHeight / 2) - (y * tileHeight / 2))
This is what I currently use for figuring out a tile position:
float xt = x + camPosition.x - (ScreenWidth/2) ;
float yt = (ScreenHeight) - y + camPosition.y - (ScreenHeight/2);
int tileY = Math.round((((xt) / tileWidth) - ((yt) / tileHeight)));
int tileX = Math.round((((xt) / tileWidth) + ((yt) / tileHeight))- 1);
I'm just wondering how I could update these to allow for more precise coordinates, instead of tile only. EDIT: Following what ccxvii said below, and removing the -1 from tileX, the object follows my mouse just like I had wanted. Just going to re-examine the math and figure out if that change will result in other messes =o
© Game Development or respective owner