Reputation: 523
I have an SKLabelNode that increments by one point every time my player touches an object:
let scoreLabel = childNodeWithName("points") as! Points
scoreLabel.increment()
However, I have an SKScene that pops up when my player hits an enemy. In the SKScene, I have labels set up for "High score", regular scoring and a tap to play again:
score.text = String(format: "%d", pointsLabel)
highScore.text = String(format: "%d", pointsLabel) //more of this code is in my GameScene
How do I connect the points label and highscore label with the pointsLabel() SKLabelNode to make the score and high score show up in my SKScene? Will post more code if necessary.
Upvotes: 0
Views: 139
Reputation: 59496
If you want to share the score
among several scenes you can save the value with NSUserDefaults
.
let score = 123
NSUserDefaults.standardUserDefaults().setInteger(score, forKey: "score")
let score = NSUserDefaults.standardUserDefaults().integerForKey("score")
Upvotes: 1