如何使此代码在 3 个不同场景的不同帧速率下正确?有例子吗?
源自 Actionscript 3.0 - 更改场景的 FPS 不起作用:
function modifyFrameRate():void {
stage.frameRate = this.currentScene.name == 'Scene 1' ? 2 : 40;
}
modifyFrameRate();
我的代码:
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();
原始代码在两种模式之间进行选择,这就是使用三元运算符的原因。如果您有更多场景,则创建一个 key:value 字典更有意义,其中场景名称是键,帧速率是值:
var SceneToRate:Object =
{
'Title': 10,
'Intro Scene': 120,
'Game': 60,
'Ending Scene': 24
}
function updateFrameRate():void
{
stage.frameRate = SceneToRate[currentScene.name];
}