Can I do a color swap like Among Us in OpenFL?

192 Views Asked by At

Can I do a color swap like Among Us in a game I am creating with Haxe, OpenFL and HaxeFlixel?

I found a sprite from Among Us that looks like this

Among Us Idle Sprite

Can I use shaders or code to make this color like the following? (When I used threshold on the Bitmap, other colors were also changed)

Among Us Black Idle Sprite

Thanks.

2

There are 2 best solutions below

0
YellowAfterlife On

You can in fact use a shader (you can find a polite introduction here(archive)) - as you can see from the sprite, the idea is essentially

out.a = in.a;
out.rgb = colorUniform1.rgb * in.r + colorUniform2.rgb * in.g + colorUniform3.rgb * in.b;
0
loudo On

You can use a shader like the HueSaturationShader that allows you to shift the colors to a different part of the spectrum. You can find an implementation for openfl here. You could use it that way:

sprite.shader = new openfl.shaders.HueSaturationShader(hue,saturation);

You can even control the color on enter frame:

//declaration
var hueShader = new HueSaturationShader();
sprite.shader = hueShader ;
//on enter frame
hueShader.data.hue.value = [0.5];