我很难让游戏分数随着时间而不是游戏事件的增加而增加。分数是游戏开始时显示的SKlabelnode。我希望分数随着游戏时间的推移而增加,然后在游戏重新开始时重新回到0(即:玩家死亡)
分数标签保持在 0,我尝试了多种代码变体
//score
var score = Int()
var highScore = Int()
let scoreLable = SKLabelNode()
scoreLable.position = CGPoint(x: self.frame.width / 1.1, y: self.frame.height / 1.1)
scoreLable.zPosition = 5
scoreLable.fontSize = 100
scoreLable.fontName = "AppleSDGothicNeo-bold"
scoreLable.text = "\(score)"
func ScoreAndHighScore(){
score = score+1
}
var scoreTimer = Timer(timeInterval: 5.0, target: self, selector: #selector(ScoreAndHighScore), userInfo: nil, repeats: true)
最佳答案
每次分数值增加时,您都需要更新标签的文本。
func ScoreAndHighScore() {
score += 1
scoreLabel.text = "\(score)"
}
关于swift - 当按下开始按钮时,游戏分数会随着时间的推移而增加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41540182/