LibGDX精灵屏幕没有加载图形或加载屏幕

时间:2014-10-24 11:36:43

标签: java android eclipse libgdx

我的LibGDX项目中存在此问题,我基本上无法加载我的游戏屏幕,我正在关注YouTube教程(链接到我正在使用的特定教程:https://www.youtube.com/watch?v=LSblkR4K1LU),我发现了我的精灵应该放在我的屏幕上,只是它根本不会加载,它只是打开,关闭然后弹出它:http://puu.sh/coxUv/d877d08a83.png,我承认我从视频中唯一改变的是这个:

@Override
public void render(float delta) {
    Gdx.gl.glClearColor(1F, 1F, 1F, 1F);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    camera.update();    

我将GL10.GL_COLOR_BUFFER_BIT(在视频中)改为GL20.GL_COLOR_BUFFER_BIT,因为它给了我一个错误:GL10无法解析为变量,有没有人知道为什么,告诉我是否有任何需要信息。

提前致谢。

编辑:

游戏屏幕类:

package com.edac.unforgivingunderground;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;


public class GameScreen implements Screen{

UnforgivingUnderground game;
OrthographicCamera camera;
SpriteBatch batch;

public GameScreen(UnforgivingUnderground game){
    this.game = game;

    camera = new OrthographicCamera();
    camera.setToOrtho(false,1920,1080);

    batch = new SpriteBatch();

} 

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

    camera.update();

}

@Override
public void resize(int width, int height) {
    // TODO Auto-generated method stub

}

@Override
public void show() {
    // TODO Auto-generated method stub

}

@Override
public void hide() {
    // TODO Auto-generated method stub

}

@Override
public void pause() {
    // TODO Auto-generated method stub

}

@Override
public void resume() {
    // TODO Auto-generated method stub

}

@Override
public void dispose() {
    // TODO Auto-generated method stub

}

资产类别:

package com.edac.unforgivingunderground;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Sprite;

public class Assets {


public static Texture texture_back;
public static Sprite sprite_back;

public static void load(){

    texture_back = new Texture(Gdx.files.internal("logo"));
    texture_back.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    sprite_back = new Sprite(texture_back);
    sprite_back.flip(false, true);
}

}

Desktop Launcher:

package com.edac.unforgivingunderground.desktop;

import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.edac.unforgivingunderground.UnforgivingUnderground;

public class DesktopLauncher {
public static void main (String[] arg) {
    LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();

    new LwjglApplication(new UnforgivingUnderground(), config);
}

}

主类:

package com.edac.unforgivingunderground;

import com.badlogic.gdx.Game;

public class UnforgivingUnderground extends  Game{

public GameScreen game_screen;

@Override
public void create() {
    Assets.load();

    game_screen = new GameScreen(this);

    setScreen(game_screen);

}

1 个答案:

答案 0 :(得分:0)

不确定它崩溃的原因(你应该发布堆栈转储),但可能是因为这行:Gdx.files.internal("logo")。也许你的意思是logo.pnglogo.jpg。还要确保图像文件确实存在于资源文件夹中。

另外,我相信你的render方法缺少一行。:

@Override
public void render(float delta) {
    Gdx.gl.glClearColor(1F, 1F, 1F, 1F);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    camera.update();

    Assets.sprite_back.draw(batch);
}

这样你就可以通过SpriteBatch将你的精灵渲染到屏幕上。在您的代码中,您可以看到您没有使用它。