SpriteKit: callback when scene is executed?
In SpriteKit, is there a callback when the scene has completed the transition?
It doesn't look like SKView functionpresentScene
has a callback.
The alternative is for the scene to manually notify the caller after the scene goes into view, but hoped there was a cleaner approach with a natural callback.
source to share
presentScene
has no known callback when the scene has completed transitions, instead use either Notification
or create your own delegate in 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 outgoingScenes willMove(from:view)
, this is the last thing to happen during the transition. didMove(to:view)
on the incoming Stage is the beginning of the transition
source to share