Jump to content
  • Advertisement


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


mouse input on an iso tile map

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

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

Share this post

Link to post
Share on other sites
Right here is available a doc, see the bottom of the page for "Mouse Matters"


hope this helps !


Share this post

Link to post
Share on other sites
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:


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.

Share this post

Link to post
Share on other sites
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|

Share this post

Link to post
Share on other sites
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.

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!