Reputation: 3190
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)
Upvotes: 4
Views: 3374
Reputation: 3139
It is possible in pure PIXI with ColorMatrixFilter
:
let filter = new PIXI.filters.ColorMatrixFilter();
filter.matrix = [
10, 10, 10, 10,
10, 10, 10, 10,
10, 10, 10, 10,
-1, -1, -1, 1
];
sprite.filters = [filter];
AFAIK tint
and alpha
might stop working, but you can add additional filters after this one (e.g. AlphaFilter
) to achieve a similar effect.
Upvotes: 1
Reputation: 17903
You could apply a custom filter to the sprite. "Filter" is PixiJS's term for a shader.
The fragment shader should be pretty simple. Here are two good fragment shader tutorials:
Upvotes: 1
Reputation: 21
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();
Upvotes: 2