Recent versions of Flash default to a maximum frame rate of 24 frames per second. This is usually fine for animations, but changing the maximum frame rate for a game may allow you to achieve a more fluid end result. The easiest way to do this is to use the SWF
frameRate
meta tag, which is a line of code added before the Away3DTemplate
class introduced in Chapter 1, Building Your First Away3D Application.
[SWF(frameRate=100)] public class Away3DTemplate extends Sprite { // class definition goes here }
Note that setting the maximum frame rate using the frameRate
meta tag does not mean that your application will always run at a higher frame rate, just that it can run at a higher frame rate. A slow PC will still run an Away3D application at a low frame rate even if the maximum frame rate has been set to a high value.
You also need to be aware that any calculations performed in the onEnterFrame()
function, such as transforming a 3D object, can be dependent on the frame rate of the application. In the following code, we rotate a 3D object by 1 degree around the X-axis every frame. This kind of transformation has been common throughout the examples provided in this book.
override protected function onEnterFrame(event:Event):void { super.onEnterFrame(event); shipModel.rotationX += 1; }
If the frame rate is 30 FPS, the 3D object will rotate around the X-axis by 30 degrees every second. If the frame rate is 90 FPS, the 3D object will rotate around the X-axis by 90 degrees every second. If your application requires these kinds of transformations to be performed consistently regardless of the frame rate, you can use a tweening library like the one demonstrated in Chapter 3, Moving Objects.