How do I dynamically color sprites

Get help using Construct 2

Post » Mon Sep 15, 2014 6:19 pm

http://brandontreb.com/cocos2d-tutorial-dynamically-coloring-sprites

After reading this brief tutorial I was wondering if something like this is possible with Construct 2? And more specifically, has anyone accomplished it? I have my doubts but I thought I'd ask anyway as someone usually comes up with something new eventually!

I thought about it a bit trying to use webgl effects and using the setColor but I don't think it's as precise because it colors the sprite as a whole, so the skin tone would be lost unless you separate the body from the head and attach a unique head to body. The problem with that is now there are two sprites for every one sprite that you would have had, if you created them all individually. The same goes for say, attaching accessories such as hats,glasses, and hairstyles. so I'm not sure how that would effect runtime in the long run.

Edit: One would have to build each character as 6 different sprites and have them color randomly. but how would this effect runtime with for example 400 characters made up of 5 or six sprites each?

In short does anyone have a creative suggestion for creating several animated, unique humanoid sprites such as in the example of "Bitizens" for the purpose of saving resources? Is it even practical? The alternative being that each unique sprite is drawn and brought into the game as it's own sprite rather than creating them on the fly.
Last edited by Centra on Mon Sep 15, 2014 6:31 pm, edited 1 time in total.
B
10
S
2
Posts: 80
Reputation: 995

Post » Mon Sep 15, 2014 6:25 pm

Very good question. I wonder if using the hue effect could make it work. Will try when I get home and get back to you.
B
34
S
9
G
3
Posts: 493
Reputation: 4,067

Post » Mon Sep 15, 2014 6:32 pm

I too came across that very question. As an example lets say you have a platformer and you can collect coins. I would want to use the least amount of memory possible so I would have an animated coins (say 5 frames) rendered in grey scale and would just apply HSL to get my Platinum, Gold, Silver and Copper. I end up with 4 rotating coins with increasing my memory footprint except for the engine code to handle such.
[b]Andrew Donelson[b]
Nlaak Studios, LLC
https://www.nlaak.com/
[email protected]
B
15
S
3
Posts: 66
Reputation: 1,136

Post » Mon Sep 15, 2014 7:07 pm

I don't think it's possible as such, but you can make x frames and select different ones for your sprite. If you need the sprite to also be animated, then replace the entire sprite with another one with a different color, which spawns at the same coordinate while the original is destroyed. It's not a pretty solution, but it's a workaround...
B
12
S
2
Posts: 80
Reputation: 816

Post » Mon Sep 15, 2014 7:18 pm

You're not dynamically colouring sprites then, you're changing animations / frames, which is completely different.
B
34
S
9
G
3
Posts: 493
Reputation: 4,067

Post » Mon Sep 15, 2014 7:31 pm

I'm playing with it now using setColor but it's very limiting because RGB only goes from 0 to 100.

Edit: actually set color recolors the entire sprite regardless of shading so it's not useful
Last edited by Centra on Mon Sep 15, 2014 7:34 pm, edited 1 time in total.
B
10
S
2
Posts: 80
Reputation: 995

Post » Mon Sep 15, 2014 7:32 pm

No 255?
B
34
S
9
G
3
Posts: 493
Reputation: 4,067

Post » Mon Sep 15, 2014 7:41 pm

It looks like the effect "Replace Color" might be the way to go, it seems to include 255

Regarding performance i think the manual discourages this entire practice

Performance

Using too many effects can cause poor performance, especially on mobile devices. Try to only use effects when it is important to the appearance of the game.

Creating many instances of an object using effects can be very inefficient, since the effect must be processed repeatedly for small areas. If many instances need to use an effect, often it is more efficient to place all the instances on their own layer, and apply the effect to that layer instead. This can improve performance whilst producing the same visual appearance.

Never use effects to process a static effect on an object. For example, do not use the 'Grayscale' effect to make an object always appear grayscale. Instead apply the grayscale effect in an image editor and import a grayscale image to the object, without using any effects. This has the same visual result, and avoids performance-degrading effect processing. Effects like 'Grayscale' should only be used for transitions or making objects only occasionally appear grayscale.

For more information, see the manual section on performance tips.


It's not very clear to me, what it means by 'using too many effects. Whether that is too many different effects or too many objects with an effect applied to it. Thoughts?
B
10
S
2
Posts: 80
Reputation: 995

Post » Fri Sep 19, 2014 6:11 pm

It just means that in C2's case, it's better to actually make and import the same sprite in different colours than to use the effect to change it "in-engine"... Which is a shame!
B
34
S
9
G
3
Posts: 493
Reputation: 4,067

Post » Fri Sep 19, 2014 11:00 pm

How is 0-100 limiting? Just convert a 0-255 value to 0-100 with value/255*100.
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Next

Return to How do I....?

Who is online

Users browsing this forum: Norafaithrainbow, ST314, tarek2 and 30 guests