Reputation: 96
Hi i need help to stop the timer in a flash game using as 3.0, i need this to pause the game because i move some targets using the getTimer() function, i can make the targets stop their movement when the game is paused but because the getTimer() keeps running when i unpause the game the targets just dissapear from screen (their position changes too fast). is there a way of stopping the timer or a better way of moving my targets as smooth as the getTimer does? her5e is my code:
//animates targets
private function MoveTarget(e:Event) {
if (!MovieClip(parent).pauseGame) {
//get time passed
timePassed = getTimer() - lastTime;
lastTime += timePassed;
}
//move the target
this.x += dx * timePassed/1000;
//check to see if the target is offscreen
switch (targetType) {
case "small":
if ( dx > 0 && this.x > 771 ) { //left->right target
deleteTarget(false);
} else if ( dx < 0 && this.x < -26 ) { //left<-right target
deleteTarget(false);
}
break;
case "medium":
if ( dx > 0 && this.x > 790 ) { //left->right target
deleteTarget(false);
} else if ( dx < 0 && this.x < -40 ) { //left<-right target
deleteTarget(false);
}
break;
case "big":
if ( dx > 0 && this.x > 800 ) { //left->right target
deleteTarget(false);
} else if ( dx < 0 && this.x < -50 ) { //left<-right target
deleteTarget(false);
}
break;
}
}
Upvotes: 0
Views: 512
Reputation: 1865
Here is a simple solution, but I think you should learn what is timestep, it's a critical concept for game programming, see Fix Your Timestep!
if (!MovieClip(parent).pauseGame) {
//get time passed
timePassed = getTimer() - lastTime;
lastTime += timePassed;
}
else
{
lastTime = getTimer();
return;
}
Upvotes: 1