user434565
user434565

Reputation: 909

Problems with the Enterframe Event

I have been 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.

Upvotes: 1

Views: 1160

Answers (2)

Evil Activity
Evil Activity

Reputation: 889

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/

Upvotes: 2

NielsBjerg
NielsBjerg

Reputation: 701

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?

Upvotes: 1

Related Questions