Frame Rate for Game

Posted on 2011-09-13
Last Modified: 2013-11-11
Hi, I've seen different folks create ActionScript 3 games at different frame rates, but the question becomes...what is the best or most appropriate frame rate for a game? I've seen 12 FPS, 17 FPS, 24 FPS and 40 FPS, but why so many different rates?

Based on that, I assume that different types of games use different frame rates, so are there best practices for setting my frame rate?

Question by:Mr_Fulano
  • 2

Assisted Solution

oheil earned 100 total points
ID: 36534586
The frame rate should be as high as possible, but if you like to adress customers with low performance clients, like net books, you should go for low frame rates.
Actually it depends on the game you offer. Some games maybe playable with low frame rates, so why use a high one. If you offer a fast action game with non trivial graphics, a high frame rate must be used to make the game playable, which might than be not playable on a netbook.

LVL 14

Accepted Solution

tomaugerdotcom earned 400 total points
ID: 36535993
ideally, you would want to set your framerate high for any game involving animations or motion, in order to guarantee the smoothest-seeming motion. If you've ever played a first person shooter game, you know how important "FPS" (frames per second) is to the gaming community.

The problem with Flash-based games, as opposed to die-hard commercial games, is that you don't necessarily have a hard-core audience who have tweaked out their boxes for maximum juice when fragging their buds. Instead, you have a diverse audience from casual users to business users to hard-core gamers.

Taking that into account, the problem with setting a high framerate as your way to create a smooth gameplay experience, is that if the client's computer is not capable of delivering the rendered frames at the desired rate, the framerate drops - as a result of the CPU bogging down. All of a sudden that bullet traveling through the air goes into slow motion, the character's walk cycle looks like he's swimming underwater and the game's response to keyboard or mouse input becomes sluggish.

The solution is to NOT base your game update cycle on framerate AT ALL, but instead to use an independent clock, leveraging the ActionScript Timer class, to power your primary Game Update Loop.

So my advice to you is set your framerate to whatever you want - 20 - 30 fps is a good rule of thumb. You'll use that framerate for any timeline-based animations, for example if your character has a walk cycle. For updating motion, physics, collisions, etc, set up a timer.

Now that in and of itself doesn't solve the problem. The timer, when handled in this way does provide a little more numeric independence from the screen refresh rate, but if the CPU starts to bog down, the Timer events will as well. What may be surprising to some is that if you set a Timer to fire 10 times a second (equivalent to 10 fps) there OUGHT to be exactly - precisely - 100ms between each tick. But if you measure that, there's usually more. Sometimes as much as twice the amount! So if the game loop is meant to move a bullet 20 pixels every tick (every 100ms) then it stands to reason that if the tick takes longer, the bullet should have moved farther by the time we get around to updating the screen.

This sort of calculation is handled by a time delta factor that's easily calculated by checking the exact time (in milliseconds) of the current update cycle against the time of the last update cycle. You then use this factor in all of your motion calculations so that if more time has elapsed than expected, the objects move that much farther.

LVL 14

Expert Comment

ID: 36536080
So here's a bit of code:

private const INTERVAL:int = 100; // 100 ms in this example (this is SLOW by the way)
private var _lastUpdateTime:int;

private var _timer:Timer = new Timer(INTERVAL); 
_timer.addEventListener(TimerEvent.TIMER, updateLoop);

private function updateLoop(event:TimerEvent):void {
  var currentTime:int = getTimer();
  var deltaFactor:Number;
  if (_lastUpdateTime){
    deltaFactor = (currentTime - _lastUpdateTime) / INTERVAL;
  } else {
    deltaFactor = 1; // for the very first time we hit the update loop

  // ... update stuff!
  heroMC.x += heroVelocityX * deltaFactor;
  heroMC.y += heroVelocityY * deltaFactor;

  // ... more stuff

  // finally, store the current frame time for the next round!
  _lastUpdateTime = currentTime;

Open in new window

// disclaimer: code not tested, check for typos!

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question