Archived

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

Helius

isometric mouse routines??

Recommended Posts

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
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
http://www.gamedev.net/reference/programming/isotile/article747.asp

http://www.gamedev.net/reference/programming/isotile/article748.asp

hopefully, these two articles will help.

Share this post


Link to post
Share on other sites
Hey there, I''m developing an isometric game and I''ve worked out many ways of doing it, but the best way seems to be to treat each tile as a polygon and check if a point is within the polygon. This not only allows you to check for mouse pointers but for collision detection against ridges and special tiles. Take a look at: http://www.gamasutra.com/features/20000210/lander_pfv.htm

It has some good stuff and some simple source listings for C

Good Luck!
- Ben

P.S. This method of using 2D polygons can work wonders in a 2D game!

Share this post


Link to post
Share on other sites
Oops I forgot, I don''t actually treat all the tiles as polygons. First I do a simple rectangular check, to see if it''s even close to inside the tile, then is it''s within the rectangle I''ll inspect further.

Ah, you''ll figure out a smarter way! I don''t need to exsplain, just take a look at that article!
See ya,
Ben

P.S. You can e-mail me at cyberbenNOSPAM@home.com
Just remove the NOSPAM. Thanks!

Share this post


Link to post
Share on other sites