无限循环(动作脚本3) [英] Infinite Loops (Action Script 3)

查看:128
本文介绍了无限循环(动作脚本3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Flash Actionscript的新手,因为我的编程课使用它。我通常使用C ++(或它的一个变体)并且涉猎Java,所以Actionscript对我来说是最熟悉的。

I'm new to Flash Actionscript because my programming class uses it. I normally use C++ (or a variant of it) and have dabbled in Java, so Actionscript was mostly familiar to me.

但是,每当我使用while循环时,AS3都会在15秒后崩溃。我需要使用while循环,否则整个代码的范围将结束,并且游戏将停止在我假定的代码上运行。用我的普通编程语言,虽然(true)会挂起游戏除非,但我有Waitframe();在代码中的某个地方让它前进一帧。但是我搜索了一下,而Actionscript没有这样的东西,而我发现的只是无限循环就是魔鬼aaaaaaaa。

However, whenever I use a while loop, AS3 crashes after 15 seconds. I need to use a while loop otherwise the scope of the entire code will end and the game will stop running on code I presume. In my normal programming language, while (true) will hang the game unless I have Waitframe(); somewhere in the code to let it progress a frame. But I search, and Actionscript has no such thing, and all I've found are "Infinite loops are the devil aaaaaaaa".

Soooo,我应该如何用这个来制作游戏?我希望我的游戏持续15秒以上,但是AS3会在挂起时有帮助地终止脚本,尽管我正在做一些事情(尽管这些东西实际上并没有显示出来,大概是因为脚本挂起了)。我是否错过了允许长时间使用while循环的等待功能,还是我做错了?

Soooo, how am I supposed to be able to make a game with this? I want my game to last more than 15 seconds, yet AS3 "helpfully" terminates the script should it "hang", despite me doing stuff (although that stuff doesn't really show up at all, presumably because the script hangs). Did I miss a wait function that allows for prolonged while loop usage, or am I doing it wrong?

推荐答案

Flash可以在帧系统,本质上是按帧率计时器。
将所有游戏代码放入一个新函数中,并使用事件监听器调用该函数。

Flash works on a "Frame" system, essentially a timer by frame rate. Put all your game code in a new function and call that function using an event listener.

stage.addEventListener(Event.ENTER_FRAME, function(e:Event):void {
  // Your code here
  // Called every frame
});

这篇关于无限循环(动作脚本3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆