libGDX仅编译黑屏

时间:2014-02-08 16:03:54

标签: java android macos libgdx

已解决!!! 似乎图片的大小不成比例,例如64x64,128x128

制作了一个基本的Hello World,这个编译好了,但是当我尝试显示基本图形时,所有显示的都是黑色。基本上按照一个单词的教程,它似乎仍然这样做。任何人的想法?

package com.me.mygdxgame;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class MyGdxGame implements ApplicationListener {

SpriteBatch batch;
BitmapFont font;
Texture mario;





    @Override
    public void create() {
        mario = new Texture(Gdx.files.internal("mario.jpeg"));
        batch = new SpriteBatch();
        font = new BitmapFont();
        font.setColor(Color.CYAN);
    }

    @Override
    public void dispose() {
        batch.dispose();
        font.dispose();
    }

    @Override
    public void render() {      
        Gdx.gl.glClearColor(1, 1, 1, 1);
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

        batch.begin();
        batch.draw(mario, 200, 200);
        batch.end();

    }

    @Override
    public void resize(int width, int height) {
    }

    @Override
    public void pause() {
    }

    @Override
    public void resume() {
    }
}

刚刚意识到出现了错误代码。文件名绝对正确。

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: data/mario.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:142)
    at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:133)
    at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:112)
    at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:104)
    at com.me.mygdxgame.MyGdxGame.create(MyGdxGame.java:30)
    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: data/mario.png (Internal)
    at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:133)
    at com.badlogic.gdx.files.FileHandle.length(FileHandle.java:563)
    at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:218)
    at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)
    ... 8 more

2 个答案:

答案 0 :(得分:3)

  

引起:com.badlogic.gdx.utils.GdxRuntimeException:找不到文件:data / mario.png(内部)

在数据文件夹中找不到图像“mario.png”。确保您在android资源文件夹中有图像(Android项目 - &gt;资产 - &gt;数据 - &gt; mario.png)。

您可能想要了解如何阅读堆栈跟踪(Big long error report thing),它将为您节省大量时间。

修改:Here is link for you on stack-traces

答案 1 :(得分:2)

Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: data/mario.png (Internal)

他找不到mario.png。如果您不使用Assets文件夹,我建议您创建包含所有资源的另一个源文件夹。之后,您可以调用Gdx.input.classpath(String classpath)从实际导出的.jar加载文件,而无需对路径进行硬编码。