Skip to content

Instantly share code, notes, and snippets.

@metaphore
metaphore / Test.java
Last active November 22, 2019 12:41
[LibGDX] Remove actor from parent after animation
Group group;
Actor actor;
// ...
group.addActor(actor);
// ...
// Remove target actor after animation has been finished
@metaphore
metaphore / TintableRegionDrawable.java
Last active December 24, 2024 11:02
[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) {
@metaphore
metaphore / PixmapFromTexture.java
Last active May 24, 2025 11:53
[LibGDX] How to obtain pixmap from texture
TextureData textureData = getTexture().getTextureData();
if (!textureData.isPrepared()) {
textureData.prepare();
}
Pixmap pixmap = textureData.consumePixmap();
@metaphore
metaphore / ResizeTexture.java
Last active March 22, 2023 07:04
[LibGDX] Resize texture on load
Pixmap pixmap200 = new Pixmap(Gdx.files.internal("200x200.png"));
Pixmap pixmap100 = new Pixmap(100, 100, pixmap200.getFormat());
pixmap100.drawPixmap(pixmap200,
0, 0, pixmap200.getWidth(), pixmap200.getHeight(),
0, 0, pixmap100.getWidth(), pixmap100.getHeight()
);
Texture texture = new Texture(pixmap100);
pixmap200.dispose();
pixmap100.dispose();