Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.41 KB | None | 0 0
  1. let finalScore = self.score
  2. let highScore = StorageManager.loadHighScore()
  3.  
  4. let highScoreText: String
  5. let highScoreColor: UIColor
  6.  
  7. // Sets the high score label properties if the final score broke the high score
  8. if finalScore > highScore {
  9.     highScoreColor = AppColors.gold
  10.     highScoreText = "New High Score: \(finalScore)"
  11.  
  12.     StorageManager.saveNewHighScore(finalScore: finalScore)
  13. } else {
  14.     highScoreColor = .white
  15.     highScoreText = "High Score: \(highScore)"
  16. }
  17.  
  18. DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
  19.     [weak self] in
  20.  
  21.     // Removes all nodes after five seconds
  22.     self?.removeAllChildren()
  23.  
  24.     // Re-adds the background
  25.     let background = SKSpriteNode(imageNamed: "Background (About)")
  26.     background.name = "Background"
  27.     background.position = CGPoint(x: 512, y: 384)
  28.     background.zPosition = -1
  29.     self?.addChild(background)
  30.  
  31.     // Creates final result UI elements
  32.  
  33.     let finalScoreLabel = SKLabelNode()
  34.     finalScoreLabel.fontName = "Chalkduster"
  35.     finalScoreLabel.text = "Final score: \(finalScore)"
  36.     finalScoreLabel.position = CGPoint(x: 512, y: 440)
  37.     self?.addChild(finalScoreLabel)
  38.  
  39.     let highScoreLabel = SKLabelNode()
  40.     highScoreLabel.fontColor = highScoreColor
  41.     highScoreLabel.fontName = "Chalkduster"
  42.     highScoreLabel.text = highScoreText
  43.     highScoreLabel.position = CGPoint(x: 512, y: 350)
  44.     self?.addChild(highScoreLabel)
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement