Actionscript 3 AS 3.0停止计时器
大家好,我需要帮助在使用as 3.0的flash游戏中停止计时器,我需要这个来暂停游戏,因为我使用getTimer()函数移动了一些目标,我可以让目标在游戏暂停时停止移动,但是因为当我取消暂停游戏时getTimer()会继续运行,所以目标会从屏幕上消失(他们的位置变化太快)。有没有办法停止计时器,或者有更好的办法让我的目标像getTimer一样平稳移动?her5e是我的代码:Actionscript 3 AS 3.0停止计时器,actionscript-3,timer,Actionscript 3,Timer,大家好,我需要帮助在使用as 3.0的flash游戏中停止计时器,我需要这个来暂停游戏,因为我使用getTimer()函数移动了一些目标,我可以让目标在游戏暂停时停止移动,但是因为当我取消暂停游戏时getTimer()会继续运行,所以目标会从屏幕上消失(他们的位置变化太快)。有没有办法停止计时器,或者有更好的办法让我的目标像getTimer一样平稳移动?her5e是我的代码: //animates targets private function MoveTarget(e:Eve
//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;
}
}
//为目标设置动画
私有函数MoveTarget(e:事件){
if(!MovieClip(父项).pauseGame){
//打发时间
timePassed=getTimer()-lastTime;
lastTime+=已通过的时间;
}
//移动目标
此.x+=dx*时间传递/1000;
//检查目标是否在屏幕外
开关(目标类型){
案例“小”:
如果(dx>0&&this.x>771){//左->右目标
删除目标(假);
}如果(dx<0&&this.x<-26){//左0&&this.x>790){//左->右目标
删除目标(假);
}如果(dx<0&&this.x<-40){//左0&&this.x>800){//左->右目标
删除目标(假);
}否则,如果(dx<0&&this.x<-50){//left这里有一个简单的解决方案,但我认为您应该了解什么是timestep,它是游戏编程的关键概念,请参阅
太棒了!谢谢,我不知道为什么我没有想到这一点,你还修复了我在实例化新目标时遇到的另一个问题(我需要检查原因),太棒了,再次感谢!。
if (!MovieClip(parent).pauseGame) {
//get time passed
timePassed = getTimer() - lastTime;
lastTime += timePassed;
}
else
{
lastTime = getTimer();
return;
}