I am making a game and would like To display the score in such a fashion that if my score is 0 and is increased by 10, then the score should increment through all of the numbers from 0 to 10. After reaching the new score it should stop, for at least a small pause.
If, again, the score is increased by another 10, the scoreboard should increment through every number from 10 to 20 and then stop again.
I have tried using handlers but unsuccessful in getting them a pause or stop, in any way.
The example in this video demonstrates what I am trying to accomplish. If you look at the scoreboard in the top right, you will see the score constantly incrementing. Here is the url in case the above link does not work: http://www.youtube.com/watch?v=NdZ8YupmEmA&feature=fvwrel
This is the code for my Runnable to increment the score.
final Handler mHandler=new Handler();
mRunnable=new Runnable() {
public void run() {
String s = null;
++i;
s= new Integer(i).toString();
tv.setText(s);
mHandler.postDelayed(mRunnable,1000);
}
/*protected void onStop() {
mHandler.removeCallbacks(mRunnable);
}*/
};
mHandler.postDelayed(mRunnable,1000);
What I specifically need is how to get the code to stop counting.
You can simply print all the numbers between 2 end points.
Say:
And then again continue with the loop, just start with 11 this time,not 0.
I’m not sure it’ll work as you want, like in your Temple Run example. I would want to add a little
sleep()of very small amount, but yesterday I was advised not usesleep()method in Android development.EDIT:
Ok. This tutorial seems pretty easy to handle. You can apply the same logic to your score display mechanism using
Handler(as you probably guessed).