0

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)
Niranjana
  • 514
  • 5
  • 23
  • 1
    Please show the entire stack trace. Animation can only throw "/ by zero" if the frame time is zero, which it's not in the code you showed above. Something else is going on. Also, do not use Sprites with Animation. Use TextureRegions. (Use `atlas.findRegions()` instead of `atlas.createSprites()`.) Sprites are heavier weight than TextureRegions, and Animation ignores the extra data. – Tenfour04 Dec 05 '16 at 14:04
  • stack trace added. – Niranjana Dec 06 '16 at 04:27
  • You must be setting the Animation's frame duration to zero somewhere in code that you're not showing. As for the NPE...you are trying to draw a null texture region or texture instead of an actual one. – Tenfour04 Dec 07 '16 at 04:27
  • Frame duration is there.animTime += delta; inside render() – Niranjana Dec 07 '16 at 04:32
  • That's not frame duration, that's elapsed time. It's set in the constructor or in `setFrameDuration()` – Tenfour04 Dec 07 '16 at 04:36

0 Answers0