Add a New Collectible Component
Apple Game Frameworks and Technologies — by Tammy Coron (115 / 193)
👈 Set Up the Player State Machine | TOC | Configure the Physics Bodies 👉
You first learned about components in Create Your First Component. With components, the focus is on what a “thing” does versus what it is. You might believe that this focus lets you off the hook for thinking about what things are, but that isn’t the case; you still need to consider how you’ll be using your components.
In Val’s Revenge, there are three kinds of collectible items (types):
Each type serves a useful purpose:
- Key: Collect keys to unlock dungeon doors
- Food: Collect food to increase Val’s health (up to her maximum)
- Treasure: Collect treasure for bragging rights
Similar to what you did in Creating an Animation Component, you’ll create a single file to hold the collectible component and the corresponding collectible struct that defines the collectible properties.
Creating the Collectible Struct
In the Components group, create a new file (⌘N) using the iOS Swift File template. Name the new file CollectibleComponent.swift and replace the contents…