I am attempting to write a game in Swift using SpriteKit, and I have a number of different scenes that I switch back and forth between frequently. I have recently implemented a "standard" app-wide way of doing so, using a singleton SceneManager which (for now) remembers the most recent Scene and can switch back to it.
Unfortunately, for reasons I do not yet understand, while it switches back to the previous scene successfully, it does not also update the view to display the scene I have just switched back to—it continues to display the scene it was on until I click in the window.
As I am able to switch tothese scenes initially without any problem, and they operate perfectly normally once the mouse click has reminded the app that it actually needs to update the screen, I am not sure what I am doing wrong here.
Here is the method that attempts to return to the previously-displayed scene:
func returnToPreviousScene() {
if self.backgroundNode != nil {
self.backgroundNode = nil
}
var log = "Returning to scene..."
if let oldScene = self.scene {
log += "Current scene: \(oldScene.sceneName)"
oldScene.removeFromParent()
}
if let scene = self.previousScene {
self.scene = scene
scene.isPaused = true
NSLog("Presenting old scene now")
self.view.presentScene(nil)
self.view.presentScene(scene)
self.view.window!.makeFirstResponder(scene)
scene.isPaused = false
self.returnControl()
self.previousScene = nil
} else {
log += "no current scene (?!)"
}
if let partyScene = self.scene as? TGPartyScene {
self.partyNode = partyScene.partyNode
} else {
self.partyNode = nil
}
NSLog("\(log); changed back to scene \(self.currentSceneName())")
}
Any assistance would be most appreciated.
Timothy Collett