isometric mouse routines??

Started by
11 comments, last by Helius 24 years ago
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).
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
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
He was refering to an isometric view, your method only works with square tiles.
----------------
Black Edge Games
----------------
That''s right, didn''t notice that he said "isometric".

/. Muzzafarath
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
Exactly !!

Does anybody know something about that??

Nacho (helius).
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?
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.
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
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.
Exactly, I wanted to know the tile x-y in the map array just for making a map editor.

Thanks all,

Helius (Nacho).

This topic is closed to new replies.

Advertisement