【发布时间】:2015-12-25 00:05:41
【问题描述】:
所以我正在制作一款运行良好的僵尸射击游戏,但是在运行了一段时间后,我遇到了这个异常:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException:
Couldn't load file: 1zom3.png
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
at com.badlogic.gdx.graphics.TextureData$Factory.loadFromFile(TextureData.java:98)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:100)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:92)
at com.lastride.game.Entity.changeState(Entity.java:51)
at com.lastride.game.Enemy.seek(Enemy.java:39)
at com.lastride.game.LastRideGame.update(LastRideGame.java:149)
at com.lastride.game.LastRideGame.render(LastRideGame.java:229)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:215)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
Caused by: java.io.IOException: Error loading pixmap:
at com.badlogic.gdx.graphics.g2d.Gdx2DPixmap.<init>(Gdx2DPixmap.java:57)
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:138)
... 9 more
我知道图像在它工作时就在那里,但似乎在运行一段时间后它崩溃了。
这是它崩溃的方法:
public void changeState(int i)
{
//changes the state and concurrently the image associated with the given state
state = i;
sprite = new Sprite(new Texture(Gdx.files.internal(name+i+suff)));//crashes here
bounding = (sprite.getBoundingRectangle());
if (sprite.getTexture().getTextureData().isPrepared()==false)
{
sprite.getTexture().getTextureData().prepare();
}
playerMap = sprite.getTexture().getTextureData().consumePixmap();
}
【问题讨论】:
-
您是否在调用
dispose处理已完成的旧纹理?如果没有,这可能是由于您的大量内存泄漏而导致的内存不足错误。如果您发布更多堆栈跟踪信息,将会有很大帮助。 -
我照你说的做了,发布了更多的堆栈跟踪,我在需要精灵之前尝试调用 sprite.getTexture.dispoose(精灵 = 新精灵)但是这给我留下了黑色图像,没有纹理
标签: gradle libgdx textures sprite game-physics