开发者

How do you set up a run/game loop in Flash?

C开发者_运维知识库urrently, I have all my variable initialization and function definitions in the timeline's first frame, my logic in the second frame, and a command to 'go to the second frame' in the third frame.

This seems very sloppy to me, and I assume Flash developers have a better way of creating a run loop.

Thanks! -S


First of all, you shouldn't be writing all your game code on the timeline in the first place. Storing your code in an opaque binary file along with all your art assets is no fun.

Use classes and stick your code in external .as files.

Anyway to answer your question, typically, you'd use the onEnterFrame event (Event.ENTER_FRAME) in order to run your game loop.


As what Anon said, you can add the enter frame event... here is the code:

    stage.addEventListener(Event.ENTER_FRAME,<action name>);
function <action name> (event:Event):void
{
      //action here
}

just replace the with your own action name. :) Hope it helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜