I want to keep the score visible on the top left corner of the screen. I have the score talking care of. I just want to display it.
Score: x
The comment on the accepted answer on Stackoverflow suggests that BitmapFontCache
is the best way to do it, inside the render method.
BitmapFontCache.draw()
doesn't accept strings, so I cannot passScore:
BitmapFontCache.draw(batch, x, Align.topLeft);
doesn't work either.- Do I have to keep updating the score position?
EDIT
game.batch.begin();
cache.setText("Score: " + score, 500,500);
cache.draw(game.batch);
.........
or even if I placed it outside batch.begin
, if I place it directly in, I get
E/AndroidRuntime: FATAL EXCEPTION: GLThread 172645
Process: com.mygdx.game, PID: 16727
java.lang.NullPointerException: Attempt to invoke virtual method 'com.badlogic.gdx.graphics.g2d.GlyphLayout com.badlogic.gdx.graphics.g2d.BitmapFontCache.setText(java.lang.CharSequence, float, float)' on a null object reference
at com.mygdx.game.GameScreen.render(GameScreen.java:129)
at com.badlogic.gdx.Game.render(Game.java:46)
at com.mygdx.game.Gam.render(Gam.java:20)
at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:459)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1647)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1352)
E/AndroidGraphics: waiting for pause synchronization took too long; assuming deadlock and killing
Even if I remove score
variable and put everything outside batch.begin but inside render I keep getting the same error.
public void render(float delta) {
cache.setText("Score: " + 12, 500,500);
cache.draw(game.batch);