Different Scene, different framerate in AS3

33 views Asked by At

How do I make this code correct in different frame rate in 3 different scenes? Any examples?

Original from Actionscript 3.0 - Changing FPS for scenes won't work:

function modifyFrameRate():void {
    stage.frameRate = this.currentScene.name == 'Scene 1' ? 2 : 40;
}
modifyFrameRate();

My code:

function modifyFrameRate():void {
    stage.frameRate = this.currentScene.name == 'Title' ? 'Game' : 60;
    stage.frameRate = this.currentScene.name == 'Intro Scene' ? 'Game' : 60;
    stage.frameRate = this.currentScene.name == 'Game' ? 'Ending Scene' : 24;
}
modifyFrameRate();
1

There are 1 answers

0
Organis On

The original code chooses between two modes, that's why ternary operator is used. If you have more scenes, there's much more sense to create a key:value dictionary where scene names are the keys and the frame rates are values:

var SceneToRate:Object =
{
    'Title': 10,
    'Intro Scene': 120,
    'Game': 60,
    'Ending Scene': 24
}

function updateFrameRate():void
{
    stage.frameRate = SceneToRate[currentScene.name];
}