MeineHTMLCodes
MeineHTMLCodes

Reputation: 559

LibGDX: How to change a single sprites color?

I try change the Color of an single sprite in LibGDX(Java). For example I want to change the color of a .png that shows a blue sheet. Like this:

Sprite sprite = new Sprite(new Texture("blue_sheet.png");
sprite.setColor(Color.RED);

There is the method sprite.setColor(Color tint), but it does nothing :( If I use SpriteBatch.setColor(Color.RED) it will work, but logically will apply the color on all sprites, and I don´t want to archieve this.

Upvotes: 3

Views: 4413

Answers (2)

Sneh
Sneh

Reputation: 3757

Its just 3 lines of code :)

Sprite sprite = new Sprite(new Texture("blue_sheet.png");

batch.setColor(Color.RED);
sprite.draw(batch);
batch.setColor(Color.WHITE);

Upvotes: 7

lighthou
lighthou

Reputation: 57

This may solve your problem.

Libgdx change color of Texture at runtime

It looks at creating a pixmap that you draw based on the pixels of your image. Based on each pixel's color your draw the according color on the pixmap.

Upvotes: 3

Related Questions