How do I replace a specific color?

Get help using Construct 2

Post » Tue Mar 25, 2014 3:56 pm

Ok, I have tried the replace color effect, but it seems to work in way different from how I thought it was. If anyone is familiar with Photoshop's indexed color mode, you have a palette box of 256 colors (255 minus the background color), you can select a specific color of a sprite and replace it with another color).

"Replace Color" effect doesn't work that way.

Is this indexed color mode I want possible in C2? I need it to make alternate palettes of my player and enemies.

please help. thanks.
B
16
S
7
Posts: 301
Reputation: 2,726

Post » Tue Mar 25, 2014 5:26 pm

"Replace Color" is the only way to replace specific colors
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Post » Wed Mar 26, 2014 10:58 am

I will try now using events. I tried replace color properties yesterday.

can you tell me what do I need to put in the parameter index for replace color? and do I need to trigger the replace color continuously or just once (like start of layout) ?
B
16
S
7
Posts: 301
Reputation: 2,726

Post » Wed Mar 26, 2014 11:29 am

sgn15 wrote:I will try now using events. I tried replace color properties yesterday.

can you tell me what do I need to put in the parameter index for replace color? and do I need to trigger the replace color continuously or just once (like start of layout) ?


You have to change those parameter:
0:The R(ed) indice of the color you want to change
1:The G(reen) indice of the color you want to change
2:The B(lue) indice of the color you want to change

3:The R(ed) indice of the color you change into
4:The G(reen) indice of the color you change into
5:The B(lue) indice of the color you change into

For exemple, to change white to black, you'd have to have:
parameter 0 = 255
parameter 1 = 255
parameter 2 = 255
parameter 3 = 0
parameter 4 = 0
parameter 5 = 0

The parameter 6 changes the tolerence, I let it to 1 personnally, basically, it indicate to change also colors close to the one you have chosen

When the effect is applied, you don't need to set it continuously, however, it is a webGL effect, and will not be visible everywhere, also, change color is kind of an intensive effect (since it has to check the colors of the picture), so I recommand having something to back it up in case it doesn't work on some computer, or if you want the user to turn it off
(the system expression Effects are supported will help you supporting configurations without webGL)
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Wed Mar 26, 2014 12:22 pm

Aphrodite wrote:
sgn15 wrote:For exemple, to change white to black, you'd have to have:
parameter 0 = 255
parameter 1 = 255
parameter 2 = 255
parameter 3 = 0
parameter 4 = 0
parameter 5 = 0

The parameter 6 changes the tolerence, I let it to 1 personnally, basically, it indicate to change also colors close to the one you have chosen

When the effect is applied, you don't need to set it continuously, however, it is a webGL effect, and will not be visible everywhere, also, change color is kind of an intensive effect (since it has to check the colors of the picture), so I recommand having something to back it up in case it doesn't work on some computer, or if you want the user to turn it off
(the system expression Effects are supported will help you supporting configurations without webGL)


I kind of got lost there. Can you answer these questions.

1. Can you explain if I need to set all 7 parameters (through events) if I only need to recolor the red parts of my character sprite?

I did this:

+On start of layout
->Enable Replace Color
->Set effect Replace Color index 3 to 0 (don't know what this means, just experimenting)

doesn't change any color

2. About the support of WebGL, it's supposed to work in browser preview, right?

3. I kind of did not understand what you meant by "system expression Effects"
https://www.scirra.com/manual/126/system-expressions
I did not saw "Effect/s" in that link?
B
16
S
7
Posts: 301
Reputation: 2,726

Post » Wed Mar 26, 2014 12:54 pm

sgn15 wrote:I kind of got lost there. Can you answer these questions.

1. Can you explain if I need to set all 7 parameters (through events) if I only need to recolor the red parts of my character sprite?

I did this:

+On start of layout
->Enable Replace Color
->Set effect Replace Color index 3 to 0 (don't know what this means, just experimenting)

doesn't change any color


Sorry for not being clear, to use this effect you have to set a color to change, then a color to replace it, it is not based on the color palette, but on the value of the color (separated in 3 values, R G and B), each of them goes from 0 to 255.

to change one color in particular, you have to know those 3 values of the color (an image editor will tell you easily), then you set those value in the effect proprieties R source, G source, B source (that means you are saying that this color will be changed to something else)

When it is done, you have to change the value of R replace, G replace, B replace to the color you want, I suppose you want to change this with events, it is indeed :

"set effect ReplaceColor, parameter index #, Value #", the parameter indexes are the one I've said before, so you would have to change the parameter 3 (to set the R replace), the parameter 4 (to set the G replace), and the parameter 5 (to set the B replace); that means that this is the color it'll change into, you can also set the tolerance, if you want color that are close enough to be changed too

Also, the webGL support works in preview (if the browser supports it, that shouldn't be a problem on desktop, except if you are using chrome on XP/Vista)

hope that helps.
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Wed Mar 26, 2014 1:31 pm

Ok. It worked! but only 1 color replace is allowed per layout? only the 2nd event works. If I remove the 2nd event, the 1st event works. If I replace the first event's condition to Every Tick, only 1st event works.

http://oi58.tinypic.com/hs83l1.jpg

I need both events to work. How can I fix it?
B
16
S
7
Posts: 301
Reputation: 2,726

Post » Wed Mar 26, 2014 6:07 pm

You should use the search function of the forums, I recently helped a guy with using ReplaceColor in this topic and it should answer your questions
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Post » Thu Mar 27, 2014 3:19 am

Ok. I understood the logic of what you posted in that thread, but not the loopindex/tokenat, etc. I only want to do it (replace color) at the start of the layout without a function. Is there something wrong with my code? I don't understand why only the 2nd event is working. I also tried putting them all in one event, the 2nd set of replace color is still only working.
B
16
S
7
Posts: 301
Reputation: 2,726

Post » Thu Mar 27, 2014 4:08 am

Your problem is that you only have 1 ReplaceColor on your object, so you can only replace 1 color.
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Next

Return to How do I....?

Who is online

Users browsing this forum: Christmas and 68 guests

cron