0

我正在尝试绘制图像,但我遇到了问题。这是代码:

@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”确实存在,它实际上出现在 Eclipse 中!

我也关不上窗户。我不得不强行退出窗口,这让我很紧张:(

谢谢!任何帮助表示赞赏!

4

2 回答 2

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
于 2013-06-22T18:04:42.930 回答
0

链接显示了用于渲染图形的简单设置。

  1. 当您初始化 Texture splashTexture 时,通常使用 libGDX 将资产保存在名为“data”的资产文件夹中。尝试将其初始化为:

    纹理 splashTexture = new Texture(Gdx.files.internal("data/intrologo.png"));

  2. 您需要在批次上调用 draw 方法,并将纹理与 x 和 y 坐标一起传递给它以绘制纹理。

    批处理.开始();

    batch.draw(splashTexture, 50, 100);

    批处理.end();

玩 x 和 y 坐标来品尝。

于 2013-06-18T15:08:44.383 回答