我试图在比赛结束后让我的分数结转到一个新的场景,当这种情况发生时,得分在0时出现。我的PlayScene中的分数设置为0默认但我需要它可以在PlayScene结束时阅读ScoreScene中的分数。请帮助!!
import SpriteKit
import AVFoundation
class PlayScene: SKScene, SKPhysicsContactDelegate {
let scoreText = SKLabelNode(fontNamed: "System-Bold")
var score = 0
override func didMoveToView(view: SKView) {
self.scoreText.text = "0"
self.scoreText.fontSize = 42
self.scoreText.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMaxY(self.frame) / 1.075)
func didBeginContact(contact:SKPhysicsContact) {
var scene = ScoreScene(size: self.size)
let skView = self.view as SKView!
skView.ignoresSiblingOrder = true
scene.scaleMode = .ResizeFill
scene.size = skView.bounds.size
skView.presentScene(scene)
func blockRunner() {
for(block, blockStatus) in self.blockStatuses {
var thisBlock = self.childNodeWithName(block)
if blockStatus.shouldRunBlock() {
blockStatus.timeGapForNextRun = random()
blockStatus.currentInterval = 0
blockStatus.isRunning = true
}
if blockStatus.isRunning {
if thisBlock!.position.x > blockMaxX {
thisBlock!.position.x -= CGFloat(self.groundSpeed)
}else {
thisBlock!.position.x = self.origBlockPositionX
blockStatus.isRunning = false
self.score++
if ((self.score % 10) == 0) {
self.groundSpeed++
}
self.scoreText.text = String(self.score)
}
}else {
blockStatus.currentInterval++
}
}
}
现在当游戏结束时,它会切换到低于
的分数场景 class ScoreScene: SKScene {
var playScene = PlayScene()
let scoreText = SKLabelNode(fontNamed: "System-Bold")
override func didMoveToView(view: SKView) {
self.scoreText.text = "score: \(playScene.score)"
self.scoreText.fontSize = 42
self.scoreText.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMaxY(self.frame) / 1.075)