Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let finalScore = self.score
- let highScore = StorageManager.loadHighScore()
- let highScoreText: String
- let highScoreColor: UIColor
- // Sets the high score label properties if the final score broke the high score
- if finalScore > highScore {
- highScoreColor = AppColors.gold
- highScoreText = "New High Score: \(finalScore)"
- StorageManager.saveNewHighScore(finalScore: finalScore)
- } else {
- highScoreColor = .white
- highScoreText = "High Score: \(highScore)"
- }
- DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
- [weak self] in
- // Removes all nodes after five seconds
- self?.removeAllChildren()
- // Re-adds the background
- let background = SKSpriteNode(imageNamed: "Background (About)")
- background.name = "Background"
- background.position = CGPoint(x: 512, y: 384)
- background.zPosition = -1
- self?.addChild(background)
- // Creates final result UI elements
- let finalScoreLabel = SKLabelNode()
- finalScoreLabel.fontName = "Chalkduster"
- finalScoreLabel.text = "Final score: \(finalScore)"
- finalScoreLabel.position = CGPoint(x: 512, y: 440)
- self?.addChild(finalScoreLabel)
- let highScoreLabel = SKLabelNode()
- highScoreLabel.fontColor = highScoreColor
- highScoreLabel.fontName = "Chalkduster"
- highScoreLabel.text = highScoreText
- highScoreLabel.position = CGPoint(x: 512, y: 350)
- self?.addChild(highScoreLabel)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement