'How i can make it without bug - Java
I have a time counter bug in the game, how to fix it? In my game, when there are 6 seconds left, the timer turns red and the animation is played, but sometimes the code freezes :(
It is this code that is bugging me, how to implement it differently:
if (mTimeLeftInMillis == 6000){
mTextViewCountDown.setTextColor(Color.RED);
mTextViewCountDown.startAnimation(zooming_second);
soundPlay(watch);
}
Here is the detailed code:
private void startTimer() {
mCountDownTimer = new CountDownTimer(mTimeLeftInMillis, 1000) {
@Override
public void onTick(long millisUntilFinished) {
mTimeLeftInMillis = millisUntilFinished;
if (mTimeLeftInMillis == 6000){
mTextViewCountDown.setTextColor(Color.RED);
mTextViewCountDown.startAnimation(zooming_second);
soundPlay(watch);
}
int minutes = (int) (mTimeLeftInMillis / 1000) / 60;
int seconds = (int) (mTimeLeftInMillis / 1000) % 60;
String timeLeftFormatted = String.format(Locale.ENGLISH, "%02d:%02d", minutes, seconds);
mTextViewCountDown.setText(timeLeftFormatted);
mTimerRunning = true;
}
@Override
public void onFinish() {
mTimerRunning = false;
TimeOutDialog();
soundPlay(time_out_sound);
mediaPlayer1.stop();
tadam_false.stop();
tadam_true.stop();
watch.stop();
mTextViewCountDown.clearAnimation();
}
}.start();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
