在Swift + Sprite Kit中更改场景的最简单方法 [英] Simplest Way To Change Scene In Swift + Sprite Kit
问题描述
我只是想知道在Swift + Sprite Kit中更改场景的最简单方法是什么?
I am just wondering what the simplest way to change scenes in Swift + Sprite Kit is?
推荐答案
在场景之间切换时,您将需要设置一个过渡,场景将如何切换到下一个并定义要过渡的场景
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.
对于过渡,
var transition:SKTransition = SKTransition.fadeWithDuration(1)
fadeWithDuration
可以用任何SKTransition
替换,可以在文档
The fadeWithDuration
can 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
关于场景定义,
var scene:SKScene = GameScene(size: self.size)
您要说明的是要过渡到的场景,在本例中为GameScene
,但应替换为要过渡到的场景.
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)
将使用已定义的过渡transition
移至上一行中设置的场景scene
.
Which will move to the scene scene
which was set up in the line prior, using the transition transition
which was also defined.
这篇关于在Swift + Sprite Kit中更改场景的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!