Thursday, December 5, 2013

How to set the frame rate in the Flash Builder Actionscript project?

In some of the games such as Tower Defense or RPG, a consistently high frame rate is necessary to maintain a smooth display of the animations. By default, an Actionscript project in the Flash Builder has a frame rate of 25. This is barely enough for a few movements on the screen. If there are tonnes of bullets or enemy armies bombarding the screen display, the players will experience a horrible game play experience (and most importantly, rate your game badly....)

So, setting the game frame rate is necessary. To do that, you need to include a simple SWF meta tag above your class definition (and AFTER your library import), as stated below:

package
{
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.geom.Rectangle;
   
    [SWF(frameRate="60", width="640", height="960",backgroundColor="0xffffff")]
    public class YourGame extends Sprite
    {
        public function YourGame()
        {


           ....

In the code, make sure you have your SWF meta tag written just before your Class. Here, a frame rate of 60 is chosen. Apart from the frame rate, you can set other configurations as well, such as width, height, background color, etc.

One thing to note is that, the effect of the frame rate "may not" be reflected if you are in the debugging mode with the Adobe AIR simulator. Therefore, don't be surprised if you still observe some lagging when debugging the game. Everything will be alright when you "Export Release Build".

1 comment:

  1. Thank you, I have long been plagued with problems sized stage. Now I understand how to put the size.

    ReplyDelete