Enemies in Motion

In this game, barriers create a sense of danger. If the player collides with one of the block graphics, he or she bites the dust. The score display introduced later in this chapter rewards players each time they vault over an obstacle. Let’s take an inventory of the graphic assets that you imported earlier. The block1 picture is easy to vault because its height matches that of the avatar. The block2 image offers a tougher challenge because it’s twice as tall as the hero. You define both of them as properties of PlayScene:

let block1 = SKSpriteNode(imageNamed:"block1")let block2 = SKSpriteNode(imageNamed:"block2")

After defining the blocks as SKSpriteNodes, you need to set their positions. You want ...

Get Learning Swift™ Programming 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.