好日子,Libgdx:基本评分系统
我一直想为我的游戏创建一个简单的评分系统,并遇到了问题。我想知道是否有人可以帮我调试我的代码。首先,我遇到的问题是我的代码重复显示了我当前的分数,但每次输入一个触摸命令时,它都会重叠上一次的当前分数。
我想要我的程序做的是,只要它收到一个触摸命令,它就会添加我的分数,然后在屏幕上打印当前分数。
有人可以帮我调试我的代码,并给我一个简单的指南,这将有助于我构建我的分数系统。
这里是我的代码:
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
}
我不明白这一点。这是同一件事。 –
ell justTouched只给你一个回叫,而isTouched给你一个连续的回叫,直到你触及 –