2014-11-04 60 views
0
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 
# 

我有一个资产加载到Libgdx Java项目时出现问题,它运行一会儿(没有资产,只是黑屏),然后程序关闭。当我注释行:“batch.draw(Assets.sprite_back,0,0);”它正常运行,屏幕是白色的,它不关闭。我不认为这是代码问题 - 我所做的一切都与Youtube教程中显示的一样。Libgdx - 正在加载资产

下面是代码:

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); 
    } 
} 
+0

确保LwjglApplicationConfiguration#useGL30设置为false。 – Xoppa 2014-11-04 11:49:29

+0

这是该文件中的所有代码吗?当你实现屏幕时,应该还有一个实现的方法显示你初始化你的纹理。 – ilikeyoyo 2014-11-05 00:07:48

回答

0

你assset永远不会加载,精灵为空,你从来没有在你的代码中调用加载和accsedes尚未分配的精灵。

不是我喜欢做的这种方式,但试试这个:

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


Asset.load(); 


} 

也许这将是更好的方法显示。