changing 2d sprite color at runtime, help needed

Hello, i’m working on a 2d action side-scroller game, when the player finish the game, he will obtain player’s suits, these suits will have some power to give to the game replay value, each suit must have it’s own color.

i need to change the original suit color (dark blue with some details in light blue), to 5 or 6 new colors, each color for one suit, i tried already with the setpixels, but i didn’t obtain good results, the setpixels make a pause when it is copying and replacing the pixels colors and the colors that i have obtained didn’t look so well.

i want to find a way (shader, particle effect, or whatever) to avoid to make all the animations of the main player character in the 5 or 6 colors.

i tried on google, but didn’t found any way that will help me.

if someone can point to me to a page, thread or article to help me to figure out this, will be very appreciate.

thank you in advance for all the help.

Hi enzoravo,

the simplest way to do this would be to make two textures for suit, one with the parts that don’t change, and another one containing parts that have to change color, in grayscale. The second one can then be easily colored.

hi, thank you for the answer.

what function i need to use to change the color of the grayscale areas ?

i did that, when i used the setpixels, but the colors didn’t look so well.

You don’t have to modify the pixels manually.
You can just change the color in the material when rendering.

If you still want to modify them manually, you can read the grayscale value from the texture, multiply the color you want to have by this value, and write the result back.

ohhh, got it, you mean break the suit in two parts, one with the fixed color parts (the ones that will not change never) and the one that need change when the player change suits.

just changing de color of the material assigned to the second parts (the grayscale parts) will do the trick, that is what you are trying to tell me ?

yes, exactly

1 Like

thank you @aleksandrk i will do that!