Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Helius

isometric mouse routines??

This topic is 6627 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

Hello everybody, Can anybody explain me how to implement the mouse routines that are used to get the tile the mouse is in?? Thanks in advance, Nacho (HeLiUs).

Share this post


Link to post
Share on other sites
Advertisement
It''s pretty simple really. Let''s say there are two variables that holds the current x and y position for the mouse called mouse_x and mouse_y.

To get which tile the mouse is in you just take mouse_x * TILE_WIDTH and mouse_y * TILE_HEIGHT. If you have a 2D array that holds your map you could do this:


TILE game_map[TILE_ROWS][TILE_COLS];
/* load a level here and draw it to the screen */

/* you can now access the tile that the mouse is in by doing this: */

game_map[mouse_y * TILE_HEIGHT][mouse_x * TILE_HEIGHT]



Weird explanation but it works

/. Muzzafarath

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Exactly !!

Does anybody know something about that??

Nacho (helius).

Share this post


Link to post
Share on other sites
Surely this is just a case of looking at your code to draw isometric tiles on the screen (which must surely take a tilenumber or co-ordinates of some kind, and draw that on the screen), and doing it in reverse?

Share this post


Link to post
Share on other sites
Why do you need to know what tile your mouse is in? If it is to find out what you are selecting (such as units, like in StarCraft) then you just need the XY coords of the unit. If you are telling them where to go, you don''t need to know what tile your mous is clicking on, you need to know the XY coords that your mouse is clicking on. Isometrics is merely a way of "rendering" (so to speak) the 2d scene. It is not a way of defining where things in the scene are: that''s still done with standard XY coords offset by the position of the viewpoint.

Share this post


Link to post
Share on other sites
Regardless of whether you choose to use it or not, here''s what the original poster (appeared) to be after:

sx,sy - screen mouse co-ord''s.
ox,oy - tile co-ordinates at screen origin.
width,height - width and height of tile.
tx, ty - tile mouse co-ords''s.

tx = (sy / height) + (sx / width) + ox;
ty = (sy / height) - (sx / width) + oy;

At least, that''s what I think they were after.

- Hotstone

Share this post


Link to post
Share on other sites
quote:
Original post by Cessen

Why do you need to know what tile your mouse is in? If it is to find out what you are selecting (such as units, like in StarCraft) then you just need the XY coords of the unit. If you are telling them where to go, you don''t need to know what tile your mous is clicking on, you need to know the XY coords that your mouse is clicking on.


I think you''ve missed the point. I could be wrong, but I got the impression that the original poster wanted to know which tile his mouse is in, in terms of knowing that tile''s X,Y co-ordinates. The X,Y co-ordinates dictate which tile it is, and vice versa.

Share this post


Link to post
Share on other sites
Exactly, I wanted to know the tile x-y in the map array just for making a map editor.

Thanks all,

Helius (Nacho).

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!