java - Displaying score in libgdx game -


so having trouble keeping display of score in game creating. wondering how go doing that? have far:

package com.catgame.game;  import com.badlogic.gdx.applicationadapter; import com.badlogic.gdx.gdx; import com.badlogic.gdx.inputprocessor; import com.badlogic.gdx.audio.music; import com.badlogic.gdx.audio.sound; import com.badlogic.gdx.graphics.gl20; import com.badlogic.gdx.graphics.orthographiccamera; import com.badlogic.gdx.graphics.texture; import com.badlogic.gdx.graphics.g2d.bitmapfont; import com.badlogic.gdx.graphics.g2d.sprite; import com.badlogic.gdx.graphics.g2d.spritebatch;  public class catgame extends applicationadapter implements inputprocessor { spritebatch batch; sprite cat; orthographiccamera camera; final float cat_width = 0.75f; final float cat_height = 0.50f; sound meow;  int score = 0; string scoreprint; bitmapfont scorefont;   @override public void create () {     batch = new spritebatch();     cat = new sprite(new texture(gdx.files.internal("cat.png")));     cat.setsize(cat_width,cat_height);     scorefont = new bitmapfont(gdx.files.internal("score.fnt"));     float aspectratio = (float)gdx.graphics.getheight()/             (float)gdx.graphics.getwidth();     scorefont.getdata().setscale(0.5f);       camera = new orthographiccamera(cat_height * aspectratio,                                     cat_height);     camera.position.set(cat_width/2,cat_height/2,0);      meow = gdx.audio.newsound(gdx.files.internal("meow.wav"));      gdx.input.setinputprocessor(this);      scoreprint = "hello";   }  @override public void render () {     gdx.gl.glclearcolor(0, 0, 0, 1);     gdx.gl.glclear(gl20.gl_color_buffer_bit);     camera.update();     batch.begin();     batch.setprojectionmatrix(camera.combined);     //cat.draw(batch);     scorefont.draw(batch,scoreprint,camera.position.x,camera.position.y);     batch.end(); } 

i have tried scorefont.draw() method doesn't seem work. not sure why, maybe positioning wrong since have ortho camera or something. when tried used draw font, nothing appeared. red circle in image below shows want score around.

http://imgur.com/gallery/ywff6sz/new

draw font in render method , change font colour or background colour.it might possible because black background colour match bitmapfont colour.


Comments