Jump to content
  • Advertisement
Sign in to follow this  
Dr_Asik

2D isometric: screen to tile coordinates

This topic is 2272 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'm writing an isometric 2D game and I'm having difficulty figuring precisely on which tile the cursor is. Here's a drawing:

[Not allowed to post pictures :( here's a link : http://imageshack.us.../tilespace.png/ ]

where xs and ys are screen coordinates (pixels), xt and yt are tile coordinates, W and H are tile width and tile height in pixels, respectively.

The best I could figure out so far is this:


int xtemp = xs / (W / 2);
int ytemp = ys / (H / 2);
int xt = (xs - ys) / 2;
int yt = ytemp + xt;


This seems almost correct but is giving me a very imprecise result, making it hard to select certain tiles, or sometimes it selects a tile next to the one I'm trying to click on. I don't understand why and I'd like if someone could help me understand the logic behind this.

Thanks!

Share this post


Link to post
Share on other sites
Advertisement
I wrote an article on the subject a while ago: http://www.wildbunny.co.uk/blog/2011/03/27/isometric-coordinate-systems-the-modern-way/

Hope it helps!

Cheers, Paul.

Share this post


Link to post
Share on other sites

I wrote an article on the subject a while ago: http://www.wildbunny...the-modern-way/

Hope it helps!

Cheers, Paul.
Wow, such a simple approach. I ended up using a transformation matrix composed of a translation, a rotation and a scaling, so that getting going back-and-forth between pixels and tile coordinates is as simple as applying the transformation or its inverse; but this seems even simpler.

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!