java - Atlas does not render images in order[libGDX] -
i using following class render atlas on screen:
public class animationdemo implements applicationlistener { private spritebatch batch; private textureatlas textureatlas; private animation animation; private float elapsedtime = 0; @override public void create() { batch = new spritebatch(); textureatlas = new textureatlas(gdx.files.internal("data/packone.atlas")); animation = new animation(1 / 1f, textureatlas.getregions()); } @override public void dispose() { batch.dispose(); textureatlas.dispose(); } @override public void render() { gdx.gl.glclearcolor(0, 0, 0, 1); gdx.gl.glclear(gl20.gl_color_buffer_bit); batch.begin(); //sprite.draw(batch); elapsedtime += gdx.graphics.getdeltatime(); batch.draw(animation.getkeyframe(elapsedtime, true), 0, 0); batch.end(); } @override public void resize(int width, int height) { } @override public void pause() { } @override public void resume() { } }
i beginner libgdx, above program images not rendered in order random images appear. earlier using following same . atlas file , working properly:
public class mygdxgame implements applicationlistener { private spritebatch batch; private textureatlas textureatlas; private sprite sprite; private int currentframe = 1; private string currentatlaskey = new string("0001"); @override public void create() { batch = new spritebatch(); textureatlas = new textureatlas(gdx.files.internal("data/packone.atlas")); textureatlas.atlasregion region = textureatlas.findregion("0001"); sprite = new sprite(region); sprite.setposition(gdx.graphics.getwidth() / 2 - sprite.getwidth() / 2, gdx.graphics.getheight() / 2 - sprite.getheight() / 2); sprite.scale(4.5f); timer.schedule(new timer.task() { @override public void run() { currentframe++; if (currentframe > 393) currentframe = 1; // attention! string.format() doesnt work under gwt god knows why... currentatlaskey = string.format("%04d", currentframe); sprite.setregion(textureatlas.findregion(currentatlaskey)); } } , 0, 1 / 30.0f); } @override public void dispose() { batch.dispose(); textureatlas.dispose(); } @override public void render() { gdx.gl.glclearcolor(0, 0, 0, 1); gdx.gl.glclear(gl20.gl_color_buffer_bit); batch.begin(); sprite.draw(batch); batch.end(); } @override public void resize(int width, int height) { } @override public void pause() { } @override public void resume() { } }
any hints might wrong here?
i trying adapt program screen viewport headings in how implement welcome.
edit: .atlas file located here
your atlas file isn't ordered. if call code below, ordered.
regions.sort(new comparator<atlasregion>() { @override public int compare(atlasregion o1, atlasregion o2) { return integer.parseint(o1.name) > integer.parseint(o2.name) ? 1 : -1; } });
but i'm still checking why atlas regions isn't ordered.
Comments
Post a Comment