Hi,
In my game, I need to draw a world map with all the countries. Each country has a unique color based on the owner of this country (it can be the human player or the computer).
What would be a strategy to draw each country on the map knowing that:
I have a first SDL texture with a “blank” map (only the countries borders)
I have a data file that gives, for each country, an array with transparent pixels for pixels that are outside the country and non transparent pixels for pixels inside the country border.
the color for each country can change throughout the game as the owner (human or computer) of a country can change.
I was thinking of making a texture with all countries arrays and use color modulation to display the right color, changing color for each group of countries having the same owner.
Is it a good strategy or there some other alternatives?
Thank you!
I would have each country as their own texture, with no color alteration applied.
Another alternative is to have a spritesheet with all the country textures and then clip from that texture when rendering each country to the screen.
To change the color of the rendered country, you can use the SDL_SetTextureColorMod function to manipulate the color of the texture.
If the original (unaltered) country textures are completely white, you can set them to whatever color you want dynamically using that function.
If you for example want to set a country texture to be rendered in red (and the original country texture is white), you would use the function like this: SDL_SetTextureColorMod(myTexture, 255, 0, 0);
If you also want to do some “global” alteration of all the countries at the same time, you can have a render target texture, render all the country textures onto it, then use SDL_SetTextureColorMod on that render target texture and then finally render the render target texture to the screen.
Thanks for your help. I have created a spritesheet with all countries and set the color to white in the texture. Then with color modulation, it easy to set the right final color.