Adding the Power-up Star
Many of my favorite games grant temporary invulnerability when the player picks up a Star. We will add a hyperactive Power-up Star to our game. Meet our Star:
Adding the Star class
Now that the art is in place, you can create a new Swift file named Star.swift
in your project; we will continue to organize classes into distinct files. The Star
class will be similar to the bee
class we created earlier. It will inherit from SKSpriteNode
and adhere to our GameSprite
protocol. The Star will add a lot of power to the player, so we will also give it a special SKAction
-based zany animation to make it stand out.
To create the Star
class, add the following code in your Star.swift
file:
import SpriteKit class Star: SKSpriteNode, GameSprite { var initialSize = CGSize(width: 40, height: 38) var textureAtlas:SKTextureAtlas = SKTextureAtlas(named: "Environment") var pulseAnimation = SKAction() init() { ...