Jon W
Jon W

Reputation: 593

ColorMatrixColorFilter equivlanet in libgdx

My program has a method that is supposed to take an image and a color, and turn all of the pixels in that image into that color, while keeping each pixel's transparency.

This could be easily done in Android using ColorMatrixColorFilter without having to use nested loops to go through the entire image and change each pixel individually, which is significantly slower.

However, I recently decided to switch to libgdx, which means that I can't use the ColorMatrixColorFilter. Does libgdx have any classes that will do something similar, without having me to manually change each pixel?

Upvotes: 3

Views: 564

Answers (2)

Jon W
Jon W

Reputation: 593

The best way to do this is to use textures with only white pixels (which varying alphas), and tinting them before drawing them with SpriteBatch.setColor(r,g,b,a)--just set back to Color.WHITE after.

Aside from having to pause to transform the texture pixel-by-pixel, the biggest advantage of this is that the texture doesn't need to be set in its own file, but can be put in the same TextureAtlas as all of the other textures that aren't being tinted. Because it's not necessary to bind different colored versions of the texture, SpriteBatch ends up making a lot fewer rendering calls, which means faster rendering.

Upvotes: 2

Lama
Lama

Reputation: 2966

http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/Sprite.html#setColor(com.badlogic.gdx.graphics.Color take look at setColor();

Actually I do manipulate each pixel by myself and it's not that bad. You should give it a try.

Upvotes: 1

Related Questions