Adding coins

Coins are more fun if there are two value variations. We will create two coins:

  • A Bronze Coin, worth one coin
  • A Gold Coin, worth five coins

The two coins will be distinguishable by their color, as seen here:

Adding coins

Creating the coin classes

We only need a single Coin class to create both denominations. Everything in the Coin class should look very familiar at this point. To create the Coin class, add a new file named Coin.swift and then enter the following code:

import SpriteKit class Coin: SKSpriteNode, GameSprite { var initialSize = CGSize(width: 26, height: 26) var textureAtlas: SKTextureAtlas = SKTextureAtlas(named: "Environment") var value ...

Get Swift Game Development - Third Edition 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.