我已经从纹理图集中创建了一个精灵数组。
playerSprite = atlas.createSprites("player");
在纹理图集中,玩家区域的名称为player01
,player02
和player03
。
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:/ by zero。“
我对这些错误感到沮丧,我已经在这个问题上浪费了很多时间。
请帮我解决此问题。
堆栈追踪:
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)
我也尝试过textureregion。 然后stacktrace看起来像这样:
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)