好的,在玩了一段時間後,我能夠自己回答我的問題。
我的解決方案是將switchingScenes BOOL
屬性添加到我的實現中,默認情況下初始化爲NO
。我在我的update
方法中打了我的totalTimePlayed
限制,並將isNextLevel
設置爲YES
。通過更新循環的下一次該代碼被執行:
if (self.isNextLevel) {
// if you're already in the process of switching scenes, wait
if (!self.switchingScenes) {
self.switchingScenes = YES;
LevelSwitchScene *levelSwitch = [LevelSwitchScene sceneWithSize:self.frame.size];
levelSwitch.nextLevel = @"level2";
SKTransition *transition = [SKTransition pushWithDirection:SKTransitionDirectionDown duration:0.5];
[self.view presentScene:levelSwitch transition:transition];
}
}
所以,問題是我的場景切換隻是不停地試圖再次快於現場開關可能發生更新一遍又一遍,使其凍結。通過添加switchingScenes
關鍵字,我能夠確保只調用一次該代碼塊,避免崩潰。實際的場景變化發生在10.511981秒,因此切換場景時需要注意延遲。
希望我自己的回答已經很清楚。如果有更好的方法來實現這一點,請添加您自己的解決方案。
很好的解釋。 – sangony