Jump to content
  • Advertisement
Sign in to follow this  

Isometric Mouse - Tile Coord issues

This topic is 3040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am currently trying to make an XNA isometric engine/game/pile of spaghetti using the tile set from one of the articles here (http://www.gamedev.net/reference/articles/article2026.asp).

The tile map is rendered as a png currently (for transparency):

Each tile is (0,1,2,3)*64 offset for water/grass/brown/red selections, and the same horizontally. Currently referenced directly by a bounding rectangle.

I have an array of tiles (TileGrid = new STile[10, 10,6];, STile's consisting of an x,y,layer coordinates (layers are vertical offsets by 8*layer) and a rectangle defining the tile texture within the tile sheet) that renders correctly using:

int mapXOffset = 320 - tileWidth/2; // 64x64 tiles, so 288 offset in x
int mapYOffset = 0;

// For each layer, for each y, for each x
for (int i = 0; i < 1; i++)
for (int y = 0; y < 10; y++)
for (int x = 0; x < 10; x++)
STile tile = TileGrid[x, y, i];
if (tile.render)
// TextureList is a dictionary of Texture2D
new Vector2((xpos - ypos) * 32 + mapXOffset,
(xpos + ypos) * 16 -
tile.TexRec, Color.White, 0, new Vector2(0, 0),
1, SpriteEffects.None, 1);

This renders the tiles as shown:

The offset from the top of the tile box to the top of the actual tile graphic is ~24 pixels.

When I try to go backwards:

MouseState mous = Mouse.GetState(); // Gives mouse button status, x,y

yp = mous.Y - mapYOffset; // mous.Y
xp = mous.X-mapXOffset; //(resets back to a 0,0 origin)

mx = (xp)/32;// (xpos - ypos) // Simultaneous equations
my = yp/16;// (xpos + ypos))

// coarse X/Y for the other tile maps
cx = (mx + my) / 2 -3; // I have no idea why I am subtracting 3/2 here
cy = (my - mx) / 2 -2; // without these the values are higher than expected

The issue is that this results in some skew, a tile can be in any of 3 rows or columns at once with only slight mouse movements (not across a diagonal boundary) indicating that the method is horribly messed up.

So the question: Is this where I then need to apply the mouse maps per tile (to correct the random shifts) or am I doing something wrongly.

Share this post

Link to post
Share on other sites
Can't really answer your question based on what you have provided.

I'd need to see the project as a whole to even stand a chance at puzzling out why you wound up with a bizarre fudge factor.

Share this post

Link to post
Share on other sites
Ok, the original code is rather confusing me, but I think I have some more of it now. I think though that I want to change from using these tiles as they seem rather odd compared to normal isometric tiles.

Thanks though.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!