So in my game there is score tab that will show in gameover
This is example for my tab score
This is the code :
highscoretext = (TextView)findViewById(R.id.bt);
highscoretext.setText("0");
currentscore = (TextView)findViewById(R.id.ct);
currentscore.setText(String.valueOf(gamescore));
And this is how i save the score that will display in bestscore
SharedPreferences pref = getSharedPreferences("SavedGame", MODE_PRIVATE);
SharedPreferences.Editor editor = pref.edit();
editor.putInt("totalScore", gamescore);
if (gamescore > highscore){
highscoretext.setText(String.valueOf(gamescore));
editor.putInt("highscore", gamescore);
editor.commit();
And i wonder to make an animation to my TextView
like this
So when the tab score display, the score will count from 0 to Current score that get in the game, example : 10
and when score stop count, if the score > best score, the value in best score changed
Can anyone help me?
For API >11, i suggest you to use ValueAnimator:
ValueAnimator animator = new ValueAnimator();
animator.setObjectValues(0, count);// here you set the range, from 0 to "count" value
animator.addUpdateListener(new AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
highscoretext.setText(String.valueOf(animation.getAnimatedValue()));
}
});
animator.setDuration(1000); // here you set the duration of the anim
animator.start();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With