iossprite-kitsksceneskview

SpriteKit: callback when scene is done presenting?


In SpriteKit, is there a callback when a scene has completed its transition?

It doesn't appear like the SKView presentScene function has a callback.

The alternative is to have the scene manually notify the caller after the scene moves into view, but was hoping there is a cleaner approach with a native callback.


Solution

  • presentScene has no known callback when a scene has finished transitions, instead, use either Notifications or create your own delegate of some kind on your outgoing scenes func willMove(from:view) to achieve the desired effect

    func willMove(from view:SKView)
    {
       NotificationCenter.default.post(name: "TRANSITIONCOMPLETE", object: nil)
       //or create a delegate using protocols, assign the delegate, and call it
       delegate?.finishedTransition()
    }
    

    Note, you must use the outgoingScenes willMove(from:view), this is the last thing to happen during the transition. didMove(to:view) on the incomingScene is the start of the transition