On 2010.5.18 7:43 PM, Khono Hackland wrote:
After reading all these posts, it seems to me the simplest way to do it, assuming you have to draw out all the countries anyway, is to draw a layer on the original image with each country being its own RGB value. So just draw solid colours of the countires, being as precise or vague as you care to be, not worrying about keeping to specific geometric shapes. The differences could be on just one of the RGB colour values, so (255,255,100), (255,255,95). Easy to fit them all on if you're not really worried about having high-contrast colours. The layer could be invisible to the player, so, two surfaces. One that's blitted to screen and the other with the colours that isn't. When checking for which country the mouse clicked on, as Henrique Nakashima said, just check the colour value of the modified-colour surface. Based on what colour it is, the program will know which country. You could even assign the colours simply based on alphabetical order of the countries. So country 1 = (255,255,255), 2 = (255,255,250), etc. Thus vastly simplifying the testing. And if a mouseclick is not on a country but on an ocean or something, the modified-colour surface won't have a colour there so you don't need to do any further processing on that click.
But I'm just a newb. so maybe this has huge pitfalls I don't see.
No, that's a known and good technique. Works well with irregular shapes or in 3D situations like isometric tiles. One point to emphasize is that you don't need to actually show this layer to the player, so it doesn't matter if you're using near-identical colors. Eg. just to make a cool screenshot (er, properly debug), I drew some isometric tiles with color (0,X*10,Y*10) based on their X/Y coordinates, limiting me to 25x25 maps, but for actual use I went to (0,X,Y) instead.
Just draw each tile/country/whatever a solid color to some surface mirroring the screen the player is seeing, ask "what color is the pixel the player clicked on?", then throw away or redraw the surface with your real graphics.