Switching colors in an existing image

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Mr. Strange
Party member
Posts: 101
Joined: Mon Aug 11, 2008 5:19 am

Switching colors in an existing image

Post by Mr. Strange »

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
Last edited by Mr. Strange on Tue Oct 28, 2008 5:26 pm, edited 1 time in total.
User avatar
rude
Administrator
Posts: 1051
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Switching colors in an existing image

Post by rude »

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.
Mr. Strange
Party member
Posts: 101
Joined: Mon Aug 11, 2008 5:19 am

Re: Switching colors in an existing image

Post by Mr. Strange »

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
User avatar
rude
Administrator
Posts: 1051
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Switching colors in an existing image

Post by rude »

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.
User avatar
cag
Citizen
Posts: 65
Joined: Sun Jun 29, 2008 5:09 am

Re: Switching colors in an existing image

Post by cag »

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.
u9_
Citizen
Posts: 54
Joined: Thu Oct 23, 2008 7:12 am

Re: Switching colors in an existing image

Post by u9_ »

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
User avatar
aes
Prole
Posts: 13
Joined: Sat Mar 29, 2008 2:24 am

Re: Switching colors in an existing image

Post by aes »

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 264 times
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 19 guests