When the player contacts the star, we will grant invulnerability for a short time and give the player great speed to power through encounters. Follow these steps to implement the power-up:
In
Player.swift
, add a new function to thePlayer
class, as shown here:func starPower() { // Remove any existing star power-up animation, if // the player is already under the power of star self.removeActionForKey("starPower") // Grant great forward speed: self.forwardVelocity = 400 // Make the player invulnerable: self.invulnerable = true // Create a sequence to scale the player larger, // wait 8 seconds, then scale back down and turn off // invulnerability, returning the player to normal: let starSequence = SKAction.sequence([ SKAction.scaleTo(1.5, duration: 0.3), SKAction.waitForDuration(8), SKAction.scaleTo(1, duration: 1), SKAction.runBlock { self.forwardVelocity = 200 self.invulnerable...