Reputation: 2552
I don't know the exact term for what I am looking for. I am developing a game and I am showing score in other game scene. I want to change the score (Actually add current score in previous score) in such a way that is change one by one like in other games. For example if previous score in 10 and current score is 10 then I want to show it like this with speed 10 11 12 13 14 15... while adding. And when reached 20 a sound will be played like tiiiinnnnnnnn. I want to add one by one. I hope I cleared my question please provide a solution. Thanks
Upvotes: 2
Views: 2183
Reputation: 4413
Another way that works for me.
private TimerHandler timerHandler;
private long startTime = 120000; // 2 minutes for example
private void createTimer() {
final float period = 1; //one second
this.getEngine().registerUpdateHandler(timerHandler = new TimerHandler(period, new ITimerCallback() {
public void onTimePassed(final TimerHandler pTimerHandler) {
timerHandler.reset();
startTime = (long) (startTime - (period * 1000));
int seconds = (int) ((startTime / 1000) % 60);
int minutes = (int) ((startTime / 1000) / 60);
timerText.setText(String.format("%d:%02d", minutes, seconds));
}
}));
}
Upvotes: 1
Reputation: 3770
Try this,
Use Changeable text for your purpose,
ChangeableText textTime = new ChangeableText(int xPosition, int yPosition, Font mFont, "00");
then start a timer and give it delay for the speed you want to for changing
Now suppose you want to change your text from
int x = 10 to int y = 20
final Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
x++;
textTime.setText(tm);
if(x==y) {
timer.cancel();
}
}
}, 0, 100); // you can change this delay with your own
Upvotes: 2