Simplest Way To Change Scene In Swift + Sprite Kit [closed]

不问归期 提交于 2019-12-21 17:39:55

问题


I am just wondering what the simplest way to change scenes in Swift + Sprite Kit is?


回答1:


when changing between scenes, you're going to need to set up a transition, how the scene will change to the next and define which scene you want to transition to.

For the transition,

 var transition:SKTransition = SKTransition.fadeWithDuration(1)

The fadeWithDurationcan be replaced with any SKTransition a list of which can be found in the documentation https://developer.apple.com/library/prerelease/ios/documentation/SpriteKit/Reference/SKTransition_Ref/index.html

as for defining the scene,

var scene:SKScene = GameScene(size: self.size)

You're stating which scene you wish to transition to, in this case GameScene, but should be replaced with whichever scene you wish to transition to.

In order to start the transition, call:

self.view?.presentScene(scene, transition: transition)

Which will move to the scene scene which was set up in the line prior, using the transition transition which was also defined.



来源:https://stackoverflow.com/questions/27933068/simplest-way-to-change-scene-in-swift-sprite-kit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!