Как передавать информацию в SpriteKit из одной сцены в другую? В моей игре у меня две сцены: GameScene и GameOverScene. Оценка отображается в GameScene по мере ее увеличения, но как отправить эту информацию во вторую сцену?Передача данных между сценами (SpriteKit)
Эта функция вызывается, когда у игрока заканчиваются жизни, которые меняют сцену.
func changeScene(){
let secondScene = GameOverScene(size: self.size)
secondScene.scaleMode = scaleMode
let transition = SKTransition.fadeWithDuration(0.5)
self.view?.presentScene(secondScene, transition: transition)
}
Это мой gameOverScene
class GameOverScene: SKScene {
var playAgainLabel = SKLabelNode(fontNamed:"Chalkduster")
var currentScore: Int
var scoreLabel = SKLabelNode(fontNamed: "Chalkduster")
var highScore = 0
var highScoreLabel = SKLabelNode(fontNamed: "Chalkduster")
var gameScene = GameScene()
override func didMoveToView(view: SKView) {
backgroundColor = SKColor.blackColor()
playAgainLabel.text = "Click To Play Again!"
playAgainLabel.fontSize = 30
playAgainLabel.fontColor = SKColor.whiteColor()
playAgainLabel.position = CGPoint(x: frame.width/2, y: frame.height/2)
self.addChild(playAgainLabel)
if currentScore > highScore {
highScore = currentScore
}
scoreLabel.text = "Score: " + String(currentScore)
scoreLabel.fontSize = 20
scoreLabel.fontColor = SKColor.whiteColor()
scoreLabel.position = CGPoint(x: frame.width/2, y: frame.height/1.4)
self.addChild(scoreLabel)
highScoreLabel.text = "Best: " + String(highScore)
highScoreLabel.fontSize = 20
highScoreLabel.fontColor = SKColor.whiteColor()
highScoreLabel.position = CGPoint(x: frame.width/2, y: frame.height/1.6)
self.addChild(highScoreLabel)
}
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
for touch in (touches as! Set<UITouch>) {
let location = touch.locationInNode(self)
let playingScene = GameScene(size: self.size)
playingScene.scaleMode = scaleMode
let fadeTransition = SKTransition.fadeWithDuration(0.5)
self.view?.presentScene(playingScene, transition: fadeTransition)
}
}}
пожалуйста, более конкретно в вашем коде – adao7000