Sunday, 9 October 2011

Mouse cursor handling


Today FreeRCT learned at what part of the game world you point your mouse. Quite useful for querying information, or edit something. The tile cursor is the first thing that is mouse-pointer aware. It is shown as the partially visible white square behind the bump. It follows the mouse pointer as you move the mouse around perfectly.

The trick that I used is that I re-used the drawing code. Basically, to decide what the mouse pointer points at, I 'draw' a single pixel at the coordinates of the mouse, and keep a record of what sprite gets drawn. Together with the sprite the used world position is stored. The real drawing code uses that position to display the white tile cursor.
The result is a pixel-perfect positioning of the tile cursor.

Since the drawing code itself is used, this will also work for other elements in the game, such as people, stalls, and rollercoaster graphics.