The power-up star logic

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:

  1. In Player.swift, add a new function to the Player 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, ...

Get Game Development with Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.