[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Isometric Math




-How do I do "picking," identifying the tile or character a user has
clicked on? I can imagine calculating it for a flat iso landscape, but
taking height into account all I've come up with so far is to save a
bunch of bounding rectangles and test them inefficiently.


Sorry for replying indirectly. I'd deleted the original email, and the archives seem to be down.

Anyway, if you're rendering things in 3D w/ opengl, there is a straight forward trick that'll handle this, and I imagine something similar could be done for a strictly 2D isometric game.

For example I have a hex map, which is rotated into the screen to a 3/4 perspective, along with various "billboards" for game-pieces that stand on the map. You can find screenshots showing what I'm taking about here:
http://brass-golem.com/?page_id=7


Each hex and piece has an associated "mouseMap", which is the same shape with all opaque pixels converted to pure white. When reading what the mouse is pointing to, I draw one frame of the scene off screen using the mouseMaps, with each having a colorFilter that encodes a number (this way the hexes can all share the same texture, and varry only their colorFilter). So each hex mouseMap is drawn with an RGB color of (x,y,0), while game-piece mouseMaps are drawn with RGB = (0,0,id). Then I read the color of the screen pixel the mouse points to, and decode it to precisely determine what hex/piece is picked.

Hope this helps,
-Jasper