我一直无法在游戏中添加自己的自定义字体,并且想知道为什么libgdx不喜欢在我的课程被调用后设置我的新阶段?
只要项与另一项相交,就会调用该类,而主类调用此类的.render()方法。我想让它画出#34;游戏结束"到屏幕,但我在stage.act(delta)
收到错误:
Exception in thread "LWJGL Application" java.lang.NullPointerException
at com.mygdx.game.GameOverScreen.render(GameOverScreen.java:70)
at com.mygdx.game.MyGdxGame.render(MyGdxGame.java:191)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:214)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
这是我的代码:
class GameOverScreen implements Screen {
Label gameoverstring;
private Stage stage;
SpriteBatch spritebatch;
BitmapFont white;
LabelStyle headingStyle;
@Override
public void show() {
stage = new Stage();
white = new BitmapFont(Gdx.files.internal("new.fnt"), false);
headingStyle = new LabelStyle(white, Color.WHITE);
gameoverstring = new Label("game ovaaaa!", headingStyle);
gameoverstring.setFontScale(3);
stage.addActor(gameoverstring);
}
@Override
public void render(float delta) {
//gameoverstring.setPosition(0, 0);
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(delta);
stage.draw();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
}
}
答案 0 :(得分:0)
第70行(在render
方法中)的某些内容为空。有关背景信息,请参阅What is a NullPointerException, and how do I fix it?。
我怀疑您的问题是stage
中的render
为空。可能是因为尚未调用show
方法。