views:

42

answers:

2

In MXML-based apps, you set the target framerate for the app and I believe this is a core part of Flash as well. Two questions...

  1. In many games you want the game to run as fast as it can for graphical smoothness, with some upper cap like 50-100Hz. How can you have variable framerates in Flash, or is it really not how things work?
  2. What happens when an app cannot run at the target framerate? Do updates 'stack up' leading to other problems, or does Flash discard them?

I've a simple case where I'm moving a sprite from left to right at 100px/s, at 20fps it looks un-smooth. It's not jerky or anything, but you can clearly see the stepped motion, the artwork is black/white which accentuates it I think. I reckon a higher FPS is needed ideally, but on slower systems it might be too much and I don't want to run into nasty issues where I try to drive it too fast.

+2  A: 

If the ActionScript takes too much time and the player can't maintain the frame rate that was specified, the frame rate just drops. There's nothing to stack up, you just get frames generated less often. For this reason when frame rate is important it's critical to make sure the AS code is not taking more time than you have available given the desired frame rate. Also make sure all calculates for movement are based on time and not frames.

As far as animation as 20fps, yeah, it will not look smooth. Bump up the frame rate. :-)

http://www.morearty.com/blog/2006/07/17/flex-tip-a-higher-frame-rate-even-makes-text-entry-look-better/

Sam
But can you set an unlimited FPS? Is there any problem with setting it to 100 and assuming most systems will actually end up more like 30-50fps?
John
You have no benefit when setting the fps to 100. A human being can only recognize about 25 fps. Which is - as far as I know - the standard frameRate for Flex applications.
hering
@hering, that is absolutely not true. What fps the eye can see and what fps is needed to achieve smooth motion and animation and still see short bursts is complex and means that games in particular benefit from much higher fps rates. See http://www.100fps.com/how_many_frames_can_humans_see.htm and http://en.wikipedia.org/wiki/Frame_rate#How_many_frames_per_second_can_the_human_eye_see.3F
Sam
Yeah this is a common myth... generally I would say about 50fps is more realistic as a limit but even then it depends on many factors including hardware and the user.
John
+1  A: 

If Flash is unable to execute at the desired framerate, it will begin dropping frames. You can read the details of this here.

If you are dealing with framerates in Flash a lot, it can be helpful to understand the 'elastic racetrack' model that Flash uses. You can see details about it here, but the basic idea is that the amount of time spend executing code or rendering a frame can vary on a frame by frame basis.

Alan Geleynse