问题
I have created a sprite array from texture atlas like this.
playerSprite = atlas.createSprites("player");
Inside texture atlas, player regions are named as player01
, player02
and player03
.
playerAnimation = new Animation(0.5f, playerSprite);
playerAnimation.setPlayMode(PlayMode.NORMAL);
and I rendered it like this.
batch.draw(playerAnimation.getKeyFrame(animTime,true), ninja.getX(),ninja.getY(),
ninja.getWidth(),ninja.getHeight());
When I execute, this throws an error.
"Exception in thread "LWJGL Application" java.lang.ArithmeticException: / by zero."
I am getting frustrated on these error,and I already wasted a lot of time on this issue.
Please help me to resolve this issue.
Stack trace:
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)
java.lang.ArithmeticException: / by zero
at com.badlogic.gdx.graphics.g2d.Animation.getKeyFrameIndex(Animation.java:142)
at com.badlogic.gdx.graphics.g2d.Animation.getKeyFrame(Animation.java:126)
at com.badlogic.gdx.graphics.g2d.Animation.getKeyFrame(Animation.java:114)
at com.m2f.ninjagame.screens.GameScreen.drawPlayer(GameScreen.java:254)
at com.m2f.ninjagame.screens.GameScreen.batchDraw(GameScreen.java:229)
at com.m2f.ninjagame.screens.GameScreen.render(GameScreen.java:115)
at com.badlogic.gdx.Game.render(Game.java:46)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:223)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)
I tried with textureregion also. Then stacktrace looked like this:
java.lang.NullPointerException
at com.badlogic.gdx.graphics.g2d.SpriteBatch.draw(SpriteBatch.java:589)
at com.m2f.ninjagame.screens.GameScreen.drawPlayer(GameScreen.java:264)
at com.m2f.ninjagame.screens.GameScreen.batchDraw(GameScreen.java:231)
at com.m2f.ninjagame.screens.GameScreen.render(GameScreen.java:116)
at com.badlogic.gdx.Game.render(Game.java:46)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:223)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)
来源:https://stackoverflow.com/questions/40974373/animating-the-sprite-array-created-from-texture-atlas