Skip to content

Instantly share code, notes, and snippets.

@metaphore
Last active November 19, 2015 19:28
Show Gist options
  • Save metaphore/67fb7ba95edb93b622c4 to your computer and use it in GitHub Desktop.
Save metaphore/67fb7ba95edb93b622c4 to your computer and use it in GitHub Desktop.
[LibGDX] Drawable that has own color
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
public class TintableRegionDrawable extends TextureRegionDrawable {
private static final Color tmpColor = new Color();
private final Color tintColor = new Color(Color.WHITE);
public void setTint(Color tint) {
this.tintColor.set(tint);
}
@Override
public void draw(Batch batch, float x, float y, float width, float height) {
setupTintColor(batch);
super.draw(batch, x, y, width, height);
}
@Override
public void draw(Batch batch, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) {
setupTintColor(batch);
super.draw(batch, x, y, originX, originY, width, height, scaleX, scaleY, rotation);
}
private void setupTintColor(Batch batch) {
Color color = tmpColor.set(batch.getColor()).mul(tintColor);
batch.setColor(color);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment