How do I replace a specific color?

0 favourites
  • 15 posts
From the Asset Store
Creepy Sprite Font suitable font for your Dark/Horror/Halloween games.
  • 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.

  • "Replace Color" is the only way to replace specific colors

  • 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) ?

  • 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)

  • >

    > 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?

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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?

  • 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

  • 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.

  • Your problem is that you only have 1 ReplaceColor on your object, so you can only replace 1 color.

  • http://oi59.tinypic.com/10mmzok.jpg

    The problem still persists.

    combining the 2 events into 1 event results in the same problem (only light red is being replaced).

  • You're still setting the parameters for the first "ReplaceColor" on the second event

  • ok. thanks. I fixed it.

    There's something weird happening. Isn't a replace color supposed to replace all parts of the said color into the new color? there are some pixels of that said color not being replaced. I went into the image editor to check the RGB values of the color parts not being replaced and their RGB values are the same as the ones I put in the event.

    Any idea on this issue?

  • If you set the 3 first values of the ReplaceColor correctly, and Tolerance is 1, yes it should replace every pixel of that one color entirely.

    If you're saving your image as a jpeg than compression is the problem

  • I'm aware of the jpeg effect on sprites. I also checked the RGB values of the pixels not being recolored. They are the same as the pixels being recolored.

    I just checked my tolerance. It is indeed 1. I read the description of tolerance parameter and it says its value is from 0 -100, so I tried different values. The higher the value (say 100), it affects the other colors not specified as well. So the best possible value I tried that didn't recolor the colors not specified was 30. It still doesn't recolor some pixels (only sometimes).

    Basically, I keep moving my player (walking, jumping, etc.) in my platform game. Sometimes all red are recolored, sometimes there are pixels left not replaced. I think this is either it can't keep up with something graphics related just for my computer (I'm not familiar with WebGL and what could possibly affect it) or it is really a bug.

    What do you think?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)