# 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.

## 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 on other sites
There is a thread just a few down called "tile map coordinate" that deals with the same issue

##### 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 on other sites
I got better solution for this! dont use a tile with 5 colors...
tomorrow I will explain and upload some code.

lol ok ty

##### 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 positionint rectY=((MouseY+Yoffset)/TILE_H)*2; // Yoffset is the Y camera positionint 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;}elseif (PointIsInTriangle(TILE_W/2,0,TILE_W,0,TILE_W,TILE_H/2,MouseInRectX,MouseInRectY)){	RegionDX=0;	RegionDY=-1;}elseif (PointIsInTriangle(0,TILE_H/2,TILE_W/2,TILE_H,0,TILE_H,MouseInRectX,MouseInRectY)){	RegionDX=-1;	RegionDY=1;}elseif (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!)

cool, thanks

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633701
• Total Posts
3013440
×