libGDX GdxRuntimeException:无法加载file:texture.png

时间:2014-12-23 21:47:30

标签: intellij-idea libgdx assets

我已经查看了很多关于这个确切错误的主题,但是,它们似乎都没有解决我的问题。我无法让IntelliJ / libGDX找到我的asset- texture.png。我将它放在android下的assets文件夹中,但我无法让桌面识别出来。我已经尝试添加android / assets作为内容根,但这对我的问题没有任何作用。我重新加载了图像,因为显然有些人会得到损坏的图像,这些图像会给他们带来同样的错误,但这也没有做任何事情。

这是我的logcat:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: texture.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:130)
    at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:121)
    at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:100)
    at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:92)
    at com.jakevw.zbhelpers.AssetLoader.load(AssetLoader.java:21)
    at com.jakevw.ZombieBird.ZBGame.create(ZBGame.java:12)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: texture.png (Internal)
    at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136)
    at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:222)
    at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)
    ... 9 more

这是我的AssetLoader类:

package com.jakevw.zbhelpers;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class AssetLoader {

    public static Texture texture;
    public static TextureRegion bg, grass;

    public static Animation birdAnimation;
    public static TextureRegion bird, birdDown, birdUp;

    public static TextureRegion skullUp, skullDown, bar;

    public static void load() {

        texture = new Texture(Gdx.files.internal("texture.png"));
        texture.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);

        bg = new TextureRegion(texture, 0, 0, 136, 43);
        bg.flip(false, true);

        grass = new TextureRegion(texture, 0, 43, 143, 11);
        grass.flip(false, true);

        birdDown = new TextureRegion(texture, 136, 0, 17, 12);
        birdDown.flip(false, true);

        bird = new TextureRegion(texture, 153, 0, 17, 12);
        bird.flip(false, true);

        birdUp = new TextureRegion(texture, 170, 0, 17, 12);
        birdUp.flip(false, true);

        TextureRegion[] birds = { birdDown, bird, birdUp };
        birdAnimation = new Animation(0.06f, birds);
        birdAnimation.setPlayMode(Animation.PlayMode.LOOP_PINGPONG);

        skullUp = new TextureRegion(texture, 192, 0, 24, 14);
        // Create by flipping existing skullUp
        skullDown = new TextureRegion(skullUp);
        skullDown.flip(false, true);

        bar = new TextureRegion(texture, 136, 16, 22, 3);
        bar.flip(false, true);

    }

    public static void dispose() {
        // We must dispose of the texture when we are finished.
        texture.dispose();
    }

}

最后这是我的ZBGame课程:

package com.jakevw.ZombieBird;

import com.badlogic.gdx.Game;
import com.jakevw.screens.GameScreen;
import com.jakevw.zbhelpers.AssetLoader;

public class ZBGame extends Game {

    @Override
    public void create() {
        System.out.println("ZBGame Created!");
        AssetLoader.load();
        setScreen(new GameScreen());
    }

    @Override
    public void dispose() {
        super.dispose();
        AssetLoader.dispose();
    }

}

如果有人能帮我解决这个错误的错误,非常感谢你。如果你想看到额外的代码,我把它全部上传到github:https://github.com/JakeVdub/ZombieBird

谢谢!

0 个答案:

没有答案