0

I recently converted the display style of a isometric map from staggered to diamond and I can't figure out the tile picking process.

I'm well aware of the other existing threads regarding this subject and I read all of them but I haven't figured out a solution (my concentration these days is a mess).

I'm using a very basic system which consists of passing through all tiles and pick the one where the mouse points at (something like this Map.Tile.Intersects(mouse.Rect) ) and then with the help of a color map I pick the correct tile.

But I don't like this system because is pretty inefficient compared to some mathematic solutions I saw and didn't understand.

So here is the code I use to create the map :

int x = 128 * j;
int y = 64 * i;
int isoX = (6 * 64) + (x - y);
int isoY = (x + y) / 2;

128 is the tileWidth , 64 tileHeight and 6 * 64 is the xOffset

And the coordinates are like this:

enter image description here

Can somebody give me some hints or explain what I should do ?
Thank you.

user1306322
  • 8,561
  • 18
  • 61
  • 122

1 Answers1

2

If we put your formulae into a system of equations:

isoX = 6 * 64 + 128 * j - 64 * i
isoY = 128 / 2 * j + 64 / 2 * i

we can easily invert the matrix and get the equations:

i = -1/128 * isoX + 1/64  * isoY + 3
j =  1/256 * isoX + 1/128 * isoY - 3/2
Nico Schertler
  • 32,049
  • 4
  • 39
  • 70