[Swift 2] Day 8 - Code Exercise Solution


#1

Please share your code or answers with your classmates for the Day 8 Code Exercise and related Notebook Activity questions.

Share code using

Solution

Only use code or watch video solution if you’re unsure how to solve or get stuck. It’s better to attempt writing the code first.


#2

// Add comment code block in pauseGameplay() function

func pauseGameplay() {
    
    self.physicsWorld.speed = 0
    self.asteroidLayer.paused = true
    
    self.gameplayPaused = true

    // Add fade actions
    let fadeOutAction = SKAction.fadeOutWithDuration(1)
    let fadeInAction = SKAction.fadeInWithDuration(1)
    let fadeActionSequence = SKAction.sequence([fadeOutAction, fadeInAction])
    let fadeAnimation = SKAction.repeatActionForever(fadeActionSequence)
    // End Add face actions

    self.playerShip.runAction(fadeAnimation, withKey: "FadeAnimation")
}

// Add comment code block in unpauseGameplay() function

func unpauseGameplay() {

    self.physicsWorld.speed = 1
    self.asteroidLayer.paused = false
    
    self.gameplayPaused = false
    
    // Remove fade actions and set alpha back to 1
    self.playerShip.alpha = 1
    self.playerShip.removeActionForKey("FadeAnimation")
    // End Remove fade actions and set alpha back to 1
}

If you also want to fade in/out asteroids, you have to add another action for asteroidLayer and comment out the asteroidLayer.paused = true statement in pauseGameplay() function.


#3

Btw, your video is set to private, so can’t see it… :wink:


#4

Thanks @ravenshore, I’ve changed the privacy and it should be OK later!


#5

很 不错 ! :wink: Keep up the good work !