我的SpriteKit游戏正在跳过。我已将问题缩小到这些代码段。在我的override func update(_ currentTime: TimeInterval)
函数中,我进行了以下检查,看我的玩家是否已经越过障碍:
if obstacleScoreList[0].position.y < player.position.y {
obstacleScoreList.removeFirst()
score += 1
更改分数后,我将获得以下didSet:
var score = 0 {
didSet {
let stringFromNum = String(score)
var numList = [String]()
for char in stringFromNum {
numList.append(String(char))
}
switch numList.count {
case 1:
//scoreLabel3.texture = SKTexture(imageNamed: "num" + numList[0])
//blurr3.texture = SKTexture(imageNamed: "BlueNum" + numList[0])
scoreLabel3.texture = SKTexture(imageNamed: "num" + numList[0])
blurr3.texture = SKTexture(imageNamed: "BlueNum" + numList[0])
case 2:
scoreLabel3.texture = SKTexture(imageNamed: "num" + numList[1])
blurr3.texture = SKTexture(imageNamed: "BlueNum" + numList[1])
scoreLabel2.texture = SKTexture(imageNamed: "num" + numList[0])
blurr2.texture = SKTexture(imageNamed: "BlueNum" + numList[0])
case 3:
scoreLabel3.texture = SKTexture(imageNamed: "num" + numList[2])
blurr3.texture = SKTexture(imageNamed: "BlueNum" + numList[2])
scoreLabel2.texture = SKTexture(imageNamed: "num" + numList[1])
blurr2.texture = SKTexture(imageNamed: "BlueNum" + numList[1])
scoreLabel1.texture = SKTexture(imageNamed: "num" + numList[0])
blurr1.texture = SKTexture(imageNamed: "BlueNum" + numList[0])
default:
break
}
}
}
我的得分是3个SKSpriteNodes,后面还有3个SKSpriteNodes。一旦更新了分数,我就在更新这些spritenodes。如果我将score += 1
注释掉,则它运行平稳。有什么想法吗?