简体   繁体   中英

I got error with rendering sprite in Eclipse libGDX

I'm trying to make basic game in Eclipse libGDX. I have Problem with rendering sprite. I do everything like it shoud be, but I still get this Error:

LwjglGraphics: created OpenGL 3.2+ core profile (GLES 3.0) context. This is experimental! Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: BG.png at com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:148) at com.badlogic.gdx.graphics.TextureData$Factory.loadFromFile(TextureData.java:98) at com.badlogic.gdx.graphics.Texture.(Texture.java:100) at com.badlogic.gdx.graphics.Texture.(Texture.java:92) at com.zebrabandit.egghead.Assets.Load(Assets.java:13) at com.zebrabandit.egghead.GameScreen.(GameScreen.java:24) at com.zebrabandit.egghead.EggHead.create(EggHead.java:10) at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:147) at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124) Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: BG.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.(Pixmap.java:145) ... 8 more

And here is my CODE:

    public static Texture backgroundT;
    public static Sprite backgroundS;
...
        backgroundT = new Texture(Gdx.files.internal("BG.png"));
        backgroundT.setFilter(TextureFilter.Linear, TextureFilter.Linear);
        backgroundS = new Sprite(backgroundT);
        backgroundS.flip(false, true);
...
    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(1F, 1F, 1F, 1F);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        camera.update();

        batch.setProjectionMatrix(camera.combined);

        batch.begin();
            //rendering code :D
            batch.draw(Assets.backgroundS, 0, 0);
        batch.end();
    }

I assume you have initialized your project with the setup application Tool (gdx-setup.jar).

Then it's possible you are experiencing the working directory setup problem. That's what the error says(Couldn't load file)

In IDEA IDE I have to edit configuration so the working directory points to folder in project: android\\assets

File not found question was answered here

For further reference please check the video Mario Zechner has recorder to ease work the Eclipse users: Running and Debugging in Eclipse

Couldn't load file: BG.png at com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:148) at ...

I think your problem is you are trying to load a file, that is not there. Are you absolutely sure that there is a file in that location Gdx.files.internal("BG.png") .

Also you will have many problems if you are trying to load assets with uppercase characters in their names on android. So if your file is there, try renaming it to all lowercase characters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM