Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PIXI: Change only non transparent pixels of sprite to one solid color

Here is a solution that just replaces the entire texture with a solid color:

sprite.texture = PIXI.Texture.WHITE

Obviously this wont work with transparent sprites. Any transparency ends up solid as well. (Resulting in a solid rectangle)

How could I change the color of only non transparent pixels of the sprite?

(tint wont work either since all sprites would have to be white)

like image 338
ThatBrianDude Avatar asked Oct 16 '25 01:10

ThatBrianDude


1 Answers

As far as I know, you can't do it with Pixi. According to one of Pixi maintainers here, you can use dark tint from pixi-heaven package (https://github.com/gameofbombs/pixi-heaven). This exact example is listed in its readme:

Make whole sprite of one color:

sprite.tint = 0xffaacc;
sprite.color.dark[0] = sprite.color.light[0];
sprite.color.dark[1] = sprite.color.light[1];
sprite.color.dark[2] = sprite.color.light[2];
//dont forget to invalidate, after you changed dark DIRECTLY
sprite.color.invalidate();
like image 50
mcalus3 Avatar answered Oct 18 '25 13:10

mcalus3



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!