Reputation: 129
My problem is that when I tried to move to my next Scene using self.scene?.presentScene() an error message pops up and says 'presentScene is not a member of SKScene'.
import SpriteKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
/* Setup your scene here */
backgroundColor = SKColor.blackColor()
let start = SKLabelNode(fontNamed: "Chalkduster")
start.position = CGPoint (x: self.frame.width/2-75, y: self.frame.height/2+100)
start.fontSize = 35
start.text = "Start"
addChild(start)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
let MyScene = SecondScene(size: self.size)
MyScene.scaleMode = scaleMode
self.scene?.presentScene(MyScene)
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}
Upvotes: 0
Views: 170
Reputation: 59496
presentScene
is a method of SKView
, not SKScene
.
So to load a new scene you should write something like this
class GameScene: SKScene {
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let myScene = SecondScene(size: self.size)
myScene.scaleMode = scaleMode
self.view?.presentScene(myScene)
}
}
You can also present the new scene with a transition effect. In this case one this method and pass a SKTransition as second param.
self.view?.presentScene(myScene, transition: SKTransition.crossFadeWithDuration(1))
In the example above I am using a Cross Fade transition having a duration of 1 second. But there are many other transitions to choose from.
Upvotes: 1