[SDL] Mouse interaction with a game map
donny.viszneki at gmail.com
Sat Jul 25 13:11:11 PDT 2009
On Sat, Jul 25, 2009 at 1:18 PM, Micah Brening<micah.brening at gmail.com> wrote:
> So if I were to have a user move their mouse over the
> country or whatnot they
> wish to select,
> how can I tell what country they are over?
> Options I can figure is have a bitmap
> mask with a color per country they can select.
> The second option is an array of vertexes which would list pixels per region.
> The second seems costly. And the first seems redundant.
Both options are costly, but they cost different things. Using a
matrix (bitmap) is effectively just shipping your game with pre-cached
calculations of which region(s) each pixel represents. This costs
memory. Not caching costs less memory, and a little more CPU.
While it's certainly comparing apples to oranges, I like to tell
people that memory is much more precious these days than CPU is.
If you're tickled by hackishness as I am, you might consider using the
actual graphical pixel values to determine what the mouse is hovering
over. If you cram a region code into the lower 2 bits of three color
channels, you can represent 64 different regions, and most players
won't notice the effect it has on your artwork :P :P :P
More information about the SDL