AS 3.0停止定时器
您好,我需要帮助来停止使用 as 3.0 的 Flash 游戏中的计时器,我需要这个来暂停游戏,因为我使用 getTimer() 函数移动一些目标,我可以在游戏暂停时使目标停止移动,但是因为当我取消暂停游戏时, getTimer() 继续运行,目标从屏幕上消失(它们的位置变化太快)。有没有一种方法可以停止计时器,或者有更好的方法可以像 getTimer 一样平滑地移动我的目标? her5e 是我的代码:
//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;
}
}
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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个简单的解决方案,但我认为您应该了解什么是时间步长,这是游戏编程的关键概念,请参阅修正你的时间步长!
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!