Hi, I would like to create a timer in my space shooter game but do not know how. I would like it to go up in seconds and then stop until my Alien sprite has killed my Spaceship sprite.
// field
private int timer;
// in constructor
updateTimer();
// in act
if (++timer%60 == 0) updateTimer();
// add this method
private void updateTimer()
{
showText("Time: "+(timer/3600)+"m "+(timer/60)+"s", 80, 20);
}// field
private int timer;
// in constructor
updateTimer();
// in act
if (timer >= 0 && ++timer%60 == 0) updateTimer();
// add these methods
private void updateTimer()
{
showText("Time: "+(timer/3600)+"m "+(timer/60)+"s", 80, 20);
}
public void stopTimer()
{
timer = -1;
}