I'm making a map game, with 50+ irregularly shaped provinces. I want to fill each province depending upon which player controls it on a given turn.
What I want to do is save off a single map image, with each province filled with a unique color (greyscale, though that doesn't matter.) I would like to dynamically redirect these color values at new values after each turn. Essentially, I'm describing a dynamically palletized sprite.
Is there already code to support this? My alternative is to chop up the map, and set the color on each element as I add it to the board. That would mean storing every province as a unique image, which seems really inefficient.
--Mr. Strange
Switching colors in an existing image
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Party member
- Posts: 101
- Joined: Mon Aug 11, 2008 5:19 am
Switching colors in an existing image
Last edited by Mr. Strange on Tue Oct 28, 2008 5:26 pm, edited 1 time in total.
Re: Switching colors in an existing image
You can use love.graphics.draws to draw the sections of the image, and love.graphics.setColor to change the color of what's being drawn.
-
- Party member
- Posts: 101
- Joined: Mon Aug 11, 2008 5:19 am
Re: Switching colors in an existing image
That would be enough if my provinces were squares, but on a map of europe, I don't see an easy way to say "make Germany green and France Blue", for example. draws can't just grab an arbitrary section of a map image like that - or am I missing something?
As I said, the resource-intensive solution is to cut up the map into individual bits, draw them one at a time and use setColor to set the color of each one as I add it.
But my preferred solution would be something like
function swapColors(color1, color2) - draw all instances of color1 as color2
That would allow me to do what I want without making a hundred individual sprites.
--Mr. Strange
As I said, the resource-intensive solution is to cut up the map into individual bits, draw them one at a time and use setColor to set the color of each one as I add it.
But my preferred solution would be something like
function swapColors(color1, color2) - draw all instances of color1 as color2
That would allow me to do what I want without making a hundred individual sprites.
--Mr. Strange
Re: Switching colors in an existing image
Sorry, that's not possible. Such functionality will probably never be present at run-time, but we may get some load-time pixel processing options in the future.
You can still store multiple sprites in one image, though. I don't know your situation exactly (region size, etc), but maybe you prefer to use "100 individual sprites" instead.
You can still store multiple sprites in one image, though. I don't know your situation exactly (region size, etc), but maybe you prefer to use "100 individual sprites" instead.
Re: Switching colors in an existing image
yeah, the individual sprites will have to do, but you know, make use of tables and name your files consistently to make your life easier.
of course, if we get load-time pixel processing in the future, you could process it before-hand into different textures in memory... but it'd still probably be easier just to do individual sprites.
of course, if we get load-time pixel processing in the future, you could process it before-hand into different textures in memory... but it'd still probably be easier just to do individual sprites.
Re: Switching colors in an existing image
Would it be an idea to store only, like an alpha channel or mask of the region, and mixing it with the color of your choice somehow? It would require an image for each country separately, but only one.
I don't know how setColor works yet, so I may just be babling here.
To see what I am talking about, look at the game Triptych. If you look in the install folder you will find there are only alpha channel images of the blocks, yet they are drawn with mixed colors in the game.
Hope this helps
I don't know how setColor works yet, so I may just be babling here.
To see what I am talking about, look at the game Triptych. If you look in the install folder you will find there are only alpha channel images of the blocks, yet they are drawn with mixed colors in the game.
Hope this helps
Re: Switching colors in an existing image
I don't get it. If it's ok with one color per draw call, then love.graphics.setColorMode(love.color_modulate) does that.
- Attachments
-
- modulatetest.love
- Quick test of love.color_modulate.
- (2.81 KiB) Downloaded 411 times
Who is online
Users browsing this forum: Ahrefs [Bot] and 9 guests