Jump to content
  • Advertisement
Sign in to follow this  
Xpyder

Testing Which ISO Tile Is Selected In a Map Ed

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

Hey- i am still working on an isometric map editor, and it is going well so far except: i need REAL help on how to test which tile the mouse is over - ive looked at TANSTAAFL's article on it with the coloured box thing but i just do not get it - can someone spell it out to me please lol - btw i draw tiles like this: array [3][3][3] { 0,1,0, 1,1,0, 1,1,1, 1,1,0, 0,1,0, } //1=grass or sommat, 0 = blankness (is that a word?) but much bigger and then they are made into quads with the proper coordinates Xpy

Share this post


Link to post
Share on other sites
Advertisement
There is a thread just a few down called "tile map coordinate" that deals with the same issue

Share this post


Link to post
Share on other sites
yes, but i was hoping that someone would explain thwo the mouse map and "seperate screen with colour under tile to pick" methods work

Share this post


Link to post
Share on other sites
I got better solution for this! dont use a tile with 5 colors...
tomorrow I will explain and upload some code.

Share this post


Link to post
Share on other sites
Assuming that you are using rectangular maps (and not diamond shaped one) and you draw your tiles as: xpos-camerax,ypos-cameray then here is some code:
p.s, xoffset=camerax,yoffset=cameray

inline bool PointIsInTriangle(int x1,int y1,int x2,int y2,int x3,int y3,int x,int y) // found is some website, thanks to unknown author.
{
int a,b,c;
a = (x2 - x1) * (y - y1) - (y2 - y1) * (x - x1);
b = (x3 - x2) * (y - y2) - (y3 - y2) * (x - x2);
c = (x1 - x3) * (y - y3) - (y1 - y3) * (x - x3);
if ((a>=0 && b>=0 && c>=0) || (a<0 && b<0 && c<0))
return true;
return false;
}

int rectX=(MouseX+Xoffset)/TILE_W; // Xoffset is X the camera position
int rectY=((MouseY+Yoffset)/TILE_H)*2; // Yoffset is the Y camera position
int MouseInRectX=(MouseX+Xoffset)%TILE_W;
int MouseInRectY=(MouseY+Yoffset)%TILE_H;
int RegionDX,RegionDY;
if (PointIsInTriangle(0,0,TILE_W/2,0,0,TILE_H/2,MouseInRectX,MouseInRectY))
{
RegionDX=-1;
RegionDY=-1;
}
else
if (PointIsInTriangle(TILE_W/2,0,TILE_W,0,TILE_W,TILE_H/2,MouseInRectX,MouseInRectY))
{
RegionDX=0;
RegionDY=-1;
}
else
if (PointIsInTriangle(0,TILE_H/2,TILE_W/2,TILE_H,0,TILE_H,MouseInRectX,MouseInRectY))
{
RegionDX=-1;
RegionDY=1;
}
else
if (PointIsInTriangle(TILE_W,TILE_H/2,TILE_W,TILE_H,TILE_W/2,TILE_H,MouseInRectX,MouseInRectY))
{
RegionDX=0;
RegionDY=1;
}
else
{
RegionDX=0;
RegionDY=0;
}
xTile=rectX+RegionDX;
yTile=rectY+RegionDY;


what it actually does is finding first the square tile the mouse is over, and then it looks if you are in a triangle (one of the 4 corners) and if you do, making the right adjustments...
I know, this is alot of code, but at least you dont have to read pixels (SLOW!)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!