1

Create a SpriteKit Game Project

11:21FreeDone
2

Lay Out the Game UI

8:54FreeDone
3

Define the Game Piece Model

13:16FreeDone
4

Create the Level Model

5:47FreeDone

Draw the Rune Sprites

6:02FreeDone
6

Detecting Taps on Runes

5:27ProsDone
7

Determine Swipe Direction

6:18ProsDone
8

Add Physics to Shatter Runes

14:00ProsDone
9

Build Out the UI Text

12:24ProsDone
10

Keeping Score

8:41ProsDone
11

Displaying Score Feedback

8:18ProsDone

Draw the Rune Sprites

Published by Chris Slowik

Episode Notes

Extra tips from the author

Rune Drawing Time!

Time to do some more work in the GameScene and get these runes drawn on the board. Start by making a couple variables in the GameScene to help with the process:

var level: Level!
let runeSize = CGSize(width: 70, height: 70)

The first is of course a reference to the level, and then we make a CGSize that holds the rune size for us to reference later. This is based on the actual size of the rune sprite images, and it will be good to have the size defined in one place in case that changes.

Next, we'll add a function to determine the point for any given slot on the board. We'll need this information to be able to draw each rune in the proper position. Basically we return a Y value ranging from -226 in intervals of the rune size plus a margin of 5 - the gap defined by our design.

func pointFor(slot: Int) -> CGPoint {
    return CGPoint(x: 0.0, y: -226 + CGFloat(slot) * (runeSize.height + 5))
}

Now it's possible to write the function that draws the runes on the game board. We make a for loop that creates a sprite for each rune in the supplied array (we'll later reference the runes in the level). Note the usage of our pointFor function!

func drawRunes(for runes: [Rune]) {
    for rune in runes {
        let sprite = SKSpriteNode(imageNamed: "\(rune.runeColor)_\(rune.runeType)")
        sprite.size = runeSize
        sprite.position = pointFor(slot: rune.slot)
        sprite.name = "rune"
        addChild(sprite)
        rune.sprite = sprite
    }
}
Episode Topics: