我是Swift
和SpriteKit
的初学者。
我有gameViewController
代码:
if let scene = IntroScene(fileNamed:"IntroScene") {
// Configure the view.
let skView = self.view as! SKView
skView.showsFPS = true
skView.showsNodeCount = true
skView.ignoresSiblingOrder = true
scene.scaleMode = .AspectFill
skView.presentScene(scene)
}
}
我的应用程序从这个场景开始。我在其他viewController中为这个场景提供了一些简单动画的代码:
let introAnimationFadeIn = SKAction.fadeInWithDuration(0.05)
let introAnimation = SKAction.animateWithTextures([introAnimation1, introAnimation2, introAnimation3, introAnimation4, introAnimation5], timePerFrame: 1.5)
let sequenceIntroAnimation = SKAction.sequence([
introAnimationFadeIn,
introAnimation])
intro.runAction(sequenceIntroAnimation)
GameScene
?GameScene
时,我可以创建与其他SKSpriteNode
的segue吗?或者创建按钮会更好?
我知道segue只能用viewControllers
,但我不知道名字在游戏场景之间是如何正确的。对不起我的英语。答案 0 :(得分:3)
如果您想从一个场景转到另一个场景,则不要使用segues。 Segues是视图控制器之间的转换,而不是SKScene
s。
要展示另一个场景,只需获得SKView
并致电presentScene
!
let scene = YourSceneClass(fileNamed:"Name of your scene that is going to present")!
view.presentScene(scene) // view is an SKView
在呈现场景之前,您似乎想要制作动画。您不需要SKAction
。为什么不使用SKTransition
?
您可以使用此代码转换到淡入淡出的另一个场景:
// again, view is an SKView
view.presentScene(scene, transition: SKTransition.fadeWithDuration(1))
这很容易!