I'm having some issues drawing TextureRegions with a spriteBatch in LibGDX.
So I have a main class that hosts the game logic. In the constructor, I have:
atlas = new TextureAtlas(Gdx.files.internal("sheet.txt") );
this.loadTileGFX();
the loadTileGFX() method does this:
roseFrames = new ArrayList<AtlasRegion>();
roseFrames.add(atlas.findRegion("Dirt", 0));
roseFrames.add(atlas.findRegion("Dirt", 1));
roseFrames.add(atlas.findRegion("Dirt", 2));
roseFrames.add(atlas.findRegion("Dirt", 3));
Then I pass the arrayList of AtlasRegions into the object:
///in the main class
rsoe = new RoseSquare(roseFrames, st, col, row, tileWidth);
//in the constructor for the object to draw
this.textureRegions = roseFrames;
Then every render() loop I call:
batch.begin();
rose.draw(batch);
batch.end()
The rose.draw() method looks like this:
public void draw(SpriteBatch batch){
batch.draw(this.textureRegions.get(1), rect.x, rect.y, rect.width, rect.height);
}
But the thing is, this doesn't draw anything to the screen.
BUT HERE'S THE THING. If I change the code to be:
public void draw(SpriteBatch batch){
batch.draw(new TextureAtlas(Gdx.files.internal("sheet.txt")).findRegion("Dirt", 0)), rect.x, rect.y, rect.width, rect.height);
}
Then it draws correctly. Can anybody shed some light on what error I might have? Keep in ming I don't get any errors with the "nothing drawn" code. Also, I can trace the details of this.textureRegions.get(1), and they all are correct....
Thanks.
1
), but first texture in your second code (at index0
). Also @VeljkoAtlasRegion extends TextureRegion
– kajacx