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教程中显示的一样。
以下是代码:
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 :(得分:0)
你的assset永远不会加载,sprite为null,你永远不会在你的代码中调用加载和accsedes尚未分配的精灵。
不是我喜欢这种做法,而是试试这个:
public GameScreen(Test game){
this.game=game;
camera = new OrthographicCamera();
camera.setToOrtho(true, 1920, 1080);.
batch = new SpriteBatch();
Asset.load();
}
也许在你的方法秀中会更好。