Coloring a sprite (non-multiply)

Hi,

I’m trying to find how to change the color of all pixels in a sprite created from an image sheet. See image attached, the right-side one is what I’m trying to do.

If I use:

 sprite:setFillColor(1, 0, 0)

the sprite changes color, but the dark parts remain (pixel color is multiplied, middle sprite).

I tried a few different filter effects. filter.colorMatrix was close, but I couldn’t get it to preserve the alpha channel.

This seems like a common thing for a game to do (damage/powerup flash on a character), but nothing I’ve tried seems to work.

Does anyone know a good way to do this?

Thanks

Actually, I’ve never seen this done the way you’re suggesting in any of the engines or SDKs I’ve worked with (Corona, Torque, Unity, …)

I’ve seen the effect, but I don’t think it is achieved by fill colorizing the sprite.

I would suggest adding all an white version of the image(s) to your spritesheet and then switch to that frame + call setFillColor(1,0,0) to achieve this effect.  (You’ll have to set the fill to white when you go back to a normal image/frame.)

PS - You might be on to something with shaders and if anyone has an answer that would be great, but I think the fastest and cheapest way to solve this (computationally) is to add an extra image to your sheet.

Thanks for the ideas. I thought of the white sprite too, but I have a bunch of different sprites that I want to have this effect on so it would be a lot of extra work.

Your comment made me look through the shader effects some more, and found something that works – the duotone filter.

sprite.fill.effect = "filter.duotone" sprite.fill.effect.darkColor = { 1, 1, 1, 1 } sprite.fill.effect.lightColor = { 1, 1, 1, 1 }

This gives me a nice sprite shape that keeps the alpha channel that I can color however I want.

Thanks!

That’s great news and now I’m going to have to give it a try too.  - Sweet!

Actually, I’ve never seen this done the way you’re suggesting in any of the engines or SDKs I’ve worked with (Corona, Torque, Unity, …)

I’ve seen the effect, but I don’t think it is achieved by fill colorizing the sprite.

I would suggest adding all an white version of the image(s) to your spritesheet and then switch to that frame + call setFillColor(1,0,0) to achieve this effect.  (You’ll have to set the fill to white when you go back to a normal image/frame.)

PS - You might be on to something with shaders and if anyone has an answer that would be great, but I think the fastest and cheapest way to solve this (computationally) is to add an extra image to your sheet.

Thanks for the ideas. I thought of the white sprite too, but I have a bunch of different sprites that I want to have this effect on so it would be a lot of extra work.

Your comment made me look through the shader effects some more, and found something that works – the duotone filter.

sprite.fill.effect = "filter.duotone" sprite.fill.effect.darkColor = { 1, 1, 1, 1 } sprite.fill.effect.lightColor = { 1, 1, 1, 1 }

This gives me a nice sprite shape that keeps the alpha channel that I can color however I want.

Thanks!

That’s great news and now I’m going to have to give it a try too.  - Sweet!