Blinking because of this
override func update(currentTime: CFTimeInterval) {
if (score >= 10){
self.backgroundNode.texture = SKTexture(imageNamed: "orangebackground")
}
if (score >= 20){
self.backgroundNode.texture = SKTexture(imageNamed: "yellowbackground")
}
if (score >= 30) {
self.backgroundNode.texture = SKTexture(imageNamed: "greenbackground")
}
}
Infect inside the update method, when the rating becomes >= 10, you update the texture EVERY FRAME .
This is absolutely wrong.
, , (, 9 10 19 20 29 30).
, 10, 10 11, , .
?
shouldUpdateTexture: Bool = false, , score, score 9 10 19 20 29 30, shouldUpdateTexture true.
, update , shouldUpdateTexture, false .
class GameScene: SKScene {
private var score = 0 {
didSet {
shouldUpdateTexture = oldValue < 10 && score >= 10 || oldValue < 20 && score >= 20 || oldValue < 30 && score >= 30
}
}
private var shouldUpdateTexture = false
private var backgroundNode = SKSpriteNode(imageNamed: "defaultbackground")
override func update(currentTime: CFTimeInterval) {
if shouldUpdateTexture {
shouldUpdateTexture = false
switch score {
case 10...19: backgroundNode.texture = SKTexture(imageNamed: "orangebackground")
case 20...29: backgroundNode.texture = SKTexture(imageNamed: "yellowbackground")
case 30...Int.max: backgroundNode.texture = SKTexture(imageNamed: "yellowbackground")
default: break
}
}
}
}
.
Update
@Knight0fDragon, , , update, didSet.
:
: score , .