question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Texture Atlas not rotating regions

See original GitHub issue

Hey!

I turned on rotation in TexturePacker, but I found that libgdx wasn’t rotating them back. Looking at the code, I think this condition is wrong:

TextureAtlas ln 378:

private Sprite newSprite (AtlasRegion region) {
        if (region.packedWidth == region.originalWidth && region.packedHeight == region.originalHeight) {
            if (region.rotate) {
                Sprite sprite = new Sprite(region);
                sprite.setBounds(0, 0, region.getRegionHeight(), region.getRegionWidth());
                sprite.rotate90(true);
                return sprite;
            }
            return new Sprite(region);
        }
        return new AtlasSprite(region);
    }

Sure the widths and heights don’t match, then there is a chance it was rotated?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
MonsterOfCookiecommented, Aug 25, 2014

Hi!

From looking at your code I can see exactly what I was doing wrong. I was creating the sprites as you were but then I was using as texture regions so I was losing the rotation information!

What an idiot… Sorry for wasting your time…

0reactions
MobiDevelopcommented, Aug 24, 2014

Copied your image and the atlas file and it seems to work correctly for me…

class Test extends ApplicationAdapter {

    Batch batch;    
    AssetManager manager;
    TextureAtlas atlas;
    Array<Sprite> sprites;
    int current;

    @Override
    public void create () {
        batch = new SpriteBatch();
        manager = new AssetManager();
        manager.load("game.atlas", TextureAtlas.class);
        manager.finishLoading();
        atlas = manager.get("game.atlas", TextureAtlas.class);
        sprites = atlas.createSprites();        
    }

    @Override
    public void render () {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        batch.begin();
        sprites.get(current).draw(batch);
        batch.end();
        if (Gdx.input.justTouched()) {
            current = (current + 1) % sprites.size;
        }
    }

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

    public static void main (String[] args) {
        LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
        new LwjglApplication(new Test(), cfg);
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Rotate Atlas Region Libgdx - java - Stack Overflow
"rotation" parameter is rotating the image always from "left bottom". Can i rotate "region" from region's center point with "batch.draw"? (Note: ...
Read more >
TextureAtlas - Starling Framework Reference
getRotation(name:String):Boolean. If true, the specified region in the atlas is rotated by 90 degrees (clockwise). TextureAtlas ; getTexture(name:String):Texture.
Read more >
Edit Texture Atlas - Live2D Manuals & Tutorials
Auto-layout allows for fixed magnification, rotation, and placement of non-overlapping meshes. This setting can be specified when creating a new ...
Read more >
How to get texture region of atlas? - Godot Engine - Q&A
When using an atlas texture for sprite nodes, I've noticed that the texture of the node is not the region you selected, but...
Read more >
Apply Regions as Texture Sprite Slices
Thanks. I found it. But using rotated sprites sometimes is not comfortable. For example, when the atlas updating with new textures. Some of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found