I have a game in which the player has to do something within a defined time.
E.g.: the player has 10 seconds to complete a level.
My current code animates an imageview (it's only a horizontal line) when the game starts:
progressAnimation = new TranslateAnimation(0, -Settings.screenWidth, 0, 0);
progressAnimation.setDuration(level * 10000);
progressAnimation.setFillAfter(true);
progressAnimation.setInterpolator(new LinearInterpolator());
progressView = new ProgressView(context);
progressView.startAnimation(progressAnimation);
Simultaneously I start a handler:
handler.postDelayed(new Runnable() {
@Override
public void run() {
fireResultActivity(-1); // -1 means, time's up.
}
}, level * 10000);
If the user can finish the game within 10 seconds an activity comes up and congratulates, if they can't another, "fail" activity comes up.
Is it a good practice to use animation to indicate the progress and start a handler simultaneously?
Could you recommend other (better) solution?