我正在尝试绘制图像,但我遇到了问题。这是代码:
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0,0,0,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
splash.draw(batch);
batch.end();
}
@Override
public void show() {
Texture splashTexture = new Texture("/img/intrologo.png");
splash = new Sprite(splashTexture);
splash.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
我正试图在桌面上运行它。窗户跑了!但是我在控制台中遇到了很多错误。他们在这里:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: assets/img/intrologo.png
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:113)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: assets/img/intrologo.png
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:64)
at com.badlogic.gdx.graphics.Texture.load(Texture.java:175)
at com.badlogic.gdx.graphics.Texture.create(Texture.java:159)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:133)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:122)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:118)
at com.eamonn.blackpoint2.screens.splash.show(splash.java:32)
at com.badlogic.gdx.Game.setScreen(Game.java:62)
at com.eamonn.blackpoint2.Blackpoint2.create(Blackpoint2.java:12)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:127)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:110)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: assets/img/intrologo.png (Internal)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:127)
at com.badlogic.gdx.files.FileHandle.length(FileHandle.java:580)
at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:215)
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)
... 11 more
我在LibGDX的论坛上问了这个问题,但几天后我没有得到任何回复。这就像是故意被忽略了。
文件'intrologo.png'肯定存在,它实际上出现在日食中!
我也无法关闭窗口。我必须强行退出窗口,这让我很紧张:(
谢谢!任何帮助表示赞赏!
答案 0 :(得分:0)
此link显示了渲染图形的简单设置。
初始化Texture splashTexture时,通常使用libGDX将资源保存在名为“data”的资源文件夹中。尝试将其初始化为:
纹理splashTexture =新纹理(Gdx.files.internal(“data / intrologo.png”));
您需要在批处理上调用draw方法,并将纹理与x和y坐标一起传递给它以将纹理绘制到。
batch.begin();
batch.draw(splashTexture,50,100);
batch.end();
使用x和y坐标来品尝。
答案 1 :(得分:0)
尝试更改此
Texture splashTexture = new Texture("/img/intrologo.png");
到此
Texture splashTexture = new Texture(Gdx.files.internal("img/intrologo.png"));
创建纹理时,需要文件而不是路径名。 请参阅:http://libgdx.l33tlabs.org/docs/api/com/badlogic/gdx/graphics/Texture.html
在Assets文件夹中,它应该像
assets
|_img
|_intrologo.png