开发者

Problems with the Enterframe Event

I have bee开发者_如何学Gon developing a game using Flex, and used the Timer class to keep the main loop going.

However, when I tried using the enterFrame event to do the main loop, there were a few problems.

First of all, physics simulation seemed way too fast. Is the enterFrame event called more than once per frame? I set the application's global frame rate to 24, so shouldn't the application set off the event every 1/24 of a second?

And the second problem is that when the game runs like this, some MXML components that are added are not shown. I have absolutely no idea why this happens.

Help me please?!?

Thanks.


Don't count on the framerate to be even, or that the enterframe is called at a fixed interval. Even the timer-class isn't 100% accurate.

When doing timings, always use the delta between frame-updates and use that delta for your calculations. Also be sure to put in a safe-guard that the delta never exceeds some value to avoid strange behavior when the flash application freezes up for some unexpected reason.

This article explains it all perfectly: http://gafferongames.com/game-physics/fix-your-timestep/


The framerate is a desired value. If a user runs it on a slow machine, you might experience their output to be too slow. How about reverting to the good old setInterval?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜