0

我已经从这样的纹理图集中创建了一个精灵数组。

playerSprite = atlas.createSprites("player");

在纹理图集中,玩家区域被命名为player01和。player02player03

playerAnimation = new Animation(0.5f, playerSprite);
playerAnimation.setPlayMode(PlayMode.NORMAL);

我把它渲染成这样。

batch.draw(playerAnimation.getKeyFrame(animTime,true), ninja.getX(),ninja.getY(),
            ninja.getWidth(),ninja.getHeight());

当我执行时,这会引发错误。

“线程“LWJGL 应用程序”java.lang.ArithmeticException 中的异常:/ 为零。”

我对这些错误感到沮丧,我已经在这个问题上浪费了很多时间。

请帮我解决这个问题。

堆栈跟踪:

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)

我也尝试了纹理区域。然后堆栈跟踪看起来像这样:

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)
4

0 回答 0