Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


2D isometric: screen to tile coordinates


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Asik   Members   -  Reputation: 136

Like
0Likes
Like

Posted 25 April 2012 - 12:03 PM

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!

Sponsor:

#2 wildbunny   Members   -  Reputation: 550

Like
2Likes
Like

Posted 27 April 2012 - 04:32 PM

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.

#3 Servant of the Lord   Crossbones+   -  Reputation: 20377

Like
0Likes
Like

Posted 27 April 2012 - 05:06 PM

Use a mouse map to make things way easier: Isometric 'n' Hexagonal Maps Part I
(Skip down to the part labeled 'Mouse Matters' and things will become clear)
It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#4 Asik   Members   -  Reputation: 136

Like
0Likes
Like

Posted 28 April 2012 - 12:09 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS