Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 356
Crashalot Avatar asked Mar 05 '26 07:03

Crashalot


1 Answers

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

like image 119
Knight0fDragon Avatar answered Mar 06 '26 22:03

Knight0fDragon