Java Libgdx-加载资产

Java Libgdx-加载资产,java,opengl,ubuntu,libgdx,Java,Opengl,Ubuntu,Libgdx,我在将一个资产加载到libgdxjava项目时遇到了一个问题,它运行了一段时间(没有资产,只是黑屏),然后程序就关闭了。当我注释行:“batch.draw(Assets.sprite_back,0,0);”时,它正常运行,屏幕是白色的,并且没有关闭。我不认为这是代码的问题——我做的一切都是一样的,就像Youtube教程上显示的那样 代码如下: LwjglGraphics: created OpenGL 3.2+ core profile context. This is experimental

我在将一个资产加载到libgdxjava项目时遇到了一个问题,它运行了一段时间(没有资产,只是黑屏),然后程序就关闭了。当我注释行:“batch.draw(Assets.sprite_back,0,0);”时,它正常运行,屏幕是白色的,并且没有关闭。我不认为这是代码的问题——我做的一切都是一样的,就像Youtube教程上显示的那样

代码如下:

LwjglGraphics: created OpenGL 3.2+ core profile context. This is experimental!
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f7860b7ba70, pid=14137, tid=140153724778240
#
# JRE version: OpenJDK Runtime Environment (7.0_65-b32) (build 1.7.0_65-b32)
# Java VM: OpenJDK 64-Bit Server VM (24.65-b04 mixed mode linux-amd64 compressed oops)
# Derivative: IcedTea 2.5.3
# Distribution: Ubuntu 14.04 LTS, package 7u71-2.5.3-0ubuntu0.14.04.1
# Problematic frame:
# C  [libc.so.6+0x98a70]
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/jf/WorkspacelibGDX/desktop/hs_err_pid14137.log
#

您的assset从未加载,sprite为空,您从未调用代码来加载和访问尚未分配的sprite

并不是说我喜欢这样做,而是尝试一下:

public class GameScreen implements Screen {

    Test game;
    OrthographicCamera camera;
    SpriteBatch batch;

    public GameScreen(Test game){
        this.game=game;
        camera = new OrthographicCamera();
        camera.setToOrtho(true, 1920, 1080);. 
        batch = new SpriteBatch();

    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(1F, 1F, 1F, 1F);
        Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
        camera.update();
        batch.setProjectionMatrix(camera.combined);
        batch.begin();
        batch.draw(Assets.sprite_back, 0, 0);
        batch.end();
    }


public class Assets {

    public static Texture texture_back;
    public static Sprite sprite_back;

    public static void load(){
        texture_back = new Texture(Gdx.files.internal("menu/back.png"));
        texture_back.setFilter(TextureFilter.Linear, TextureFilter.Linear);
        sprite_back = new Sprite(texture_back);
        sprite_back.flip(false, true);
    }
}

也许在你的方法展示中会更好。

确保LwjglApplicationConfiguration#useGL30设置为false。该文件中的代码都是这些吗?当您实现屏幕时,还应该有一个实现的方法来显示初始化纹理的位置。
public GameScreen(Test game){
    this.game=game;
    camera = new OrthographicCamera();
    camera.setToOrtho(true, 1920, 1080);. 
    batch = new SpriteBatch();


Asset.load();


}