mouse input on an iso tile map

Started by
4 comments, last by Torwin 22 years, 6 months ago
OK guys, I have a working scrolling tile engine and map editor. My problem is I can find an effecient way to determine what tile the mouse has been clicked on. I changed a rectangle map editor into an iso map editor so right now I only have the bounding box detection. This is the idea I came up with. My tiles are 128 by 64 so I was going to cut the tile into 4 different boxes evenly. From there I want to see if the mouse x and y are inside the main tile or outside and in another tile. Ok that sound confusing so let's take try this. We've recieved a mouse click and found it to be in the se quardrant of Tile 1. I want to see if the mouse click is on then NW side or edge of that quadrant and thus will be in Tile 1. If this statement is false it will be in Tile 2. Does this sound resonable or not. I've be told that a Dot Product might help me with this but I can't seem to figure out how to use it to help me. Any suggestion for this method or any other will be very appreciative. Edited by - Torwin on October 15, 2001 9:55:41 AM
Advertisement
Right here is available a doc, see the bottom of the page for "Mouse Matters"

http://www.gamedev.net/reference/articles/article747.asp

hope this helps !

djsomers
djsomers;)make it idiot proof and someone makes a better idiot!
divide the iso map into rectangular sections. each rectangular section should contain all of one tile, and a quarter of each of four other tiles. create a rectangular look up table that tells you, based on what pixel in that rectangular area you are examining which of the 5 tiles contained either wholly or partially within that rectangle.

so, if you had a 16x8 tile (which you probably don''t), your lookup table would look like this:

1111110000222222
1111000000002222
1100000000000022
0000000000000000
3300000000000044
3333000000004444
3333330000444444
3333333344444444

assuming that tile (0,0) has the upper left corner at world position (0,0), you first divide by tile width and tile height to see which box you are in.

column = x / TILEWIDTH ;
row = y / TILEHEIGHT ;

and you also need to column and row remainders

column_remainder = x % TILEWIDTH ;
row_remainder = y % TILEHEIGHT ;

(if column_remainder or row_remainder are negative, you have to adjust all of these variables, adding TILEWIDTH to column_remainder, and subtracting 1 from column, ans the same idea for row_remainder and row if row_remainder is negative)

for each positive value in column, move to the east. for each negative value, move to the west

for each positive value in row, move to the south. for each negative value, move to the north.

you will now be close to the tile. check the lookup table at the column_remainder, row_remainder location. based on which value you get, move one tile diagonally, or not at all, depending on which value you get.

Get off my lawn!

Thanks for the help guys but there is no way in hell I''m going to draw a 128 by 64 look up table for the engine. Don''t yell at me for it either, are stupid graphics people defined the tile size and I can''t get it changed. As for the resource its useful but its my math that sucks for determining the tile. I''ve sat down and tried to so equation after equation but I''m also hitting the wrong tile. If anyone like to do math for this kind of stuff these are the variables I have. I''m using 128 by 64 tiles remember.

int TileX = mouseX / TILESX;
int TileY = mouseY / TILESY * 2;
int offX = mouseX % TILESX;
int offY = mouseY % TILESY;


int M = TILESY / TILESX; //Slope
int H = TILESY / 2; //Height
int W = TILESX / 2; //Width

Trying to determine if was case the mouse point hits. Below:

------
|A /\B |
| / \ |
|/ E \|
|\ /|
| \ / |
|C \/ D|
------
Hi there,

rather than code the lookup table couldnt
you use a 128x64 bitmap where r255 = 1 g255 = 2
etc.

Just an idea

Mark
or make an image that has one color for each of the five tiles that is 128x64, and scan that into the lookup table. that''s what I do.

Get off my lawn!

This topic is closed to new replies.

Advertisement