我怎样才能让这个函数休眠一段时间?
所以这是我的问题。我设置了代码,每当我的玩家超过 a* 寻路数组中的最后一个目的地时,就会调用一个函数...
public function rakeSoil(e:Event):void {
var:Cell = Grid.getCellAt(player.x/50, player.y/50);
if (cell.isWalkable == false) {
return;
else {
//here is where i want to do the sleep code so this doesnt happen straight away? If possible.
target.sprites = [grass];
}
}
谢谢大家:)
So here's my problem. I have code set up that calls a function whenever my player is over its last destination in the a* pathfinding array...
public function rakeSoil(e:Event):void {
var:Cell = Grid.getCellAt(player.x/50, player.y/50);
if (cell.isWalkable == false) {
return;
else {
//here is where i want to do the sleep code so this doesnt happen straight away? If possible.
target.sprites = [grass];
}
}
thanks guys :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,延迟执行某些事情的“正确”方法是使用 计时器。
破解某种睡眠函数可能会导致问题,因为 Flash 在单线程中运行,因此在函数运行时您将无法执行任何其他操作,包括刷新屏幕(使您的游戏看起来好像崩溃了) ,或者至少开始滞后)。
如果您绝对确定要执行此操作,则可以调用 getTimer() 循环中的函数来查看是否已经过去了一定的毫秒数。
Generally, the "right" way to delay execution of something is to use a Timer.
Hacking up some kind of a sleep function could cause problems, since Flash runs in a single thread, so you won't be able to do anything else while your function is running, including refreshing the screen (making your game appear as if it crashed, or at least started lagging).
If you're absolutely, positively sure you want to do this, you could call the getTimer() function in a loop to see if a certain amount of miliseconds has passed.