Tile Selection (Mouse Picking)
Now comes the tricky part, what if you need to select a tile, or a character on a tile? Or more technically–how can you determine which tile your mouse is currently over? I should also mention that this process may sometimes be referred to as a “screen-to-map” conversion, taking the mouse’s screen coordinates, and converting them to map coordinates. In a regular map with rectangular tiles it’s easy, just take the x and y, divide them by tileWidth and tileHeight, then do the conversion formula: tileID = y * numCols + x (unless you use a 2D array).
Read more…
- Intro/Rendering
- Tile Selection (Mouse Picking)