Libgdx Animation not working

白昼怎懂夜的黑 提交于 2019-12-01 14:34:08

When you use TexturePacker there is an easier way to create animations.

When we want to create a run animation
First you ad all animation images to TexturePacker you have to look that every frame has the same name + underscore + frameNumber. So the name of the frames must be: run_1, run_2, run_3 etc.

When we created it we have a run.txt and run.png in our assets.

Now we can load the TextureAtlas with our AssetManager:

AssetManager assetManager = new AssetManager();
assetManager.load("run.txt", TextureAtlas.class);
assetManager.finishLoading();
TextureAtlas runAnimationAtlas = assetManager.get("run.txt", TextureAtlas.class);

With this TextureAtlas we can create our Animation:

float frameDuration = 0.1f; // the duration between the animation frames
Animation<TextureRegion> runAnimation = new Animation<TextureRegion>(frameDuration, runAnimationAtlas.findRegions("run"), Animation.PlayMode.LOOP);

And render the Animation:

batch.draw(runAnimation.getKeyFrame(stateTimer),posX, posY)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!