Last active
November 19, 2015 19:28
-
-
Save metaphore/67fb7ba95edb93b622c4 to your computer and use it in GitHub Desktop.
[LibGDX] Drawable that has own color
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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