java - Libgdx: Basic score system -


good day,

i've been trying create simple score system game , encountered problem. wondering if me debug code me. first of problem have encountered code repetitively displays current score each time input touch command overlaps previous current score.

what wanted program whenever receives touch command adds score , prints current score on screen.

can please me in debugging code , give me simple guide me in constructing score system.

here code:

timer time; spritebatch btch; int score=0,currscore = 0; bitmapfont fntscore = new bitmapfont(gdx.files.internal("fonts/pressstartk16white.fnt"),false);  public void score() {     if(gdx.input.istouched())     {         score += 20;         system.out.print("score: " + score + "\n" );         currscore = score;         return;     }     else if(gdx.input.iskeypressed(keys.s))     {         score +=30;         system.out.print("score: "+ score + "\n");         currscore = score;         return;      } }  @override public void render(float delta) {      score();     btch.begin();     fntscore.draw(btch, "score: " + currscore, 100, 100);     btch.end();     // todo auto-generated method stub  } 

clear screen before rendering somthing otherwise overlap old data

 @override     public void render(float delta) {         gdx.graphics.getglcommon().glclearcolor( 1, 0, 0, 1 );         gdx.graphics.getglcommon().glclear( gl20.gl_color_buffer_bit | gl20.gl_depth_buffer_bit );         score();         btch.begin();         fntscore.draw(btch, "score: " + currscore, 100, 100);         btch.end();         // todo auto-generated method stub      } 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -