Skip to content

LibGDX exporter

Output

Packrat writes one .atlas descriptor and one image per atlas page:

text
atlas.atlas
atlas.png

Integrate

Copy atlas.atlas and atlas.png into your game's assets/ folder. Then load the atlas and create a sprite using the exported frame name. createSprite handles trimmed frames automatically, so you do not need to calculate their packed-region coordinates yourself.

Use AssetManager instead when your game has many assets or needs asynchronous loading. It returns the same TextureAtlas described below.

Minimal example

Add this to an existing LibGDX ApplicationAdapter. Replace player_0001 with a frame name that exists in your atlas:

java
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;

public final class Demo extends ApplicationAdapter {
    private SpriteBatch batch;
    private TextureAtlas atlas;
    private Sprite sprite;

    @Override public void create() {
        batch = new SpriteBatch();
        atlas = new TextureAtlas(Gdx.files.internal("atlas.atlas"));
        sprite = atlas.createSprite("player_0001");
        sprite.setPosition(320f - sprite.getWidth() / 2f,
            180f - sprite.getHeight() / 2f);
    }

    @Override public void render() {
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        batch.begin();
        sprite.draw(batch);
        batch.end();
    }

    @Override public void dispose() { batch.dispose(); atlas.dispose(); }
}

Packrat documentation