Sign in to follow this  
cypher789

find out if mouse points to an big object on an isometric map

Recommended Posts

hi, i read some small tutorials about isometric maps and i've some questions. I wrote a little programm which draws a small isometric map without any objects. only the tiles itselves. I think i got it, how to get the position of the mouse on the map. but when i have an object, which is bigger than the tile it belongs to, how i find out if the mouse points on this object. At the moment my program would tell me that the mouse points to the tile above the tile the object belongs to if i click on the top of the object. what is better for an (very simple) diablo-like hack'n'slash, rhombus tiles or hexagonal tiles? how to handle big maps? do you load the hole map, or only the part which is currently displayed, and reload new parts while moving on the map? cypher

Share this post


Link to post
Share on other sites
First of, let's address the issue of a big map and objects in it. What you could do, is having a camera class/object. In this case, the position stored in the camera class defines what the player sees.

So, when the player clicks somewhere, you know the position of the mouse *ON THE SCREEN*. Since the camera class knows where it is on the map, you can have it "convert" the position to world position, like:


CPoint pt;
Mouse.getPosition(pt);
Camera.translatePosition(pt, TL_WORLD);
CObject *pObject = Map.getObject(pt);
if (!pObject) // Nothing at that position
return; // so return


Since the tile map is made out of "layers" it's easy to find objects. The "ground" layer contains the map tiles, and the "object" layer holds all objects on the map, such as chests, swords, enemies, the player.

As for storing an item on the map that's bigger than 1 tile: Just set those coresponding positions on the object tile-map to that object aswell. Say, a chest is defined as OBJ_CHEST and this particular chest is 2 tiles width, you just let both tiles point to the same Object. Only problem is rendering since both tiles probably want to render the same piece. But I guess you can think a solution for that.


void CMap::AddObject(const Point &pt, CObject* pObject, int nWidth, int nHeight)
{
for (int y = 0; y < nHeight; ++y)
{
for (int x = 0; x < nWidth; ++x)
{
m_TileMap[x][y] = pObject;
}
}
}


Toolmaker

Share this post


Link to post
Share on other sites
I think by "bigger than one tile" he meant "very tall" not "very fat"

Each object you draw is being drawn in some rectangular region of the screen, so test your mouse against each of these rectangles first, and only check for tiles if you don't hit one. If you want it pixel perfect, then after checking a rectangle, check to see which pixel you hit and what alpha value it has, but that can wait :)

For any post in this forum (beginners) the better tile shape is the simplest one ;)

For a big map, load little bits on the fly, unless you are in the beginners forum, in which case load the whole lot and don't worry about it unless and until it breaks later :)

Keep It Simple. Make It Work. Enchance It Later.

Seriously - 90% of these projects people post about never get finished, my own included. Better to finish one which can only handle small maps than to get bogged down loading big ones. (Unless, of course, you are writing an engine, rather than a game).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this