O'Reilly logo

Build iOS Games with Sprite Kit by Josh Smith, Jonathan Penn

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Moving Nodes on a Path

Unlike the asteroids, the enemy ships should appear to be flying around. What we want is a way to specify a path the enemy ship nodes follow as they zigzag and loop around on their way past the player’s ship. Thankfully, Sprite Kit makes that easy to do.

First, we need to add the enemy.png image to our Xcode project so we can use it in our sprite node. Drag it into the sidebar and set the options like we did before in Figure 7, Dragging and dropping files into the Xcode project.

Next, we need to decide when to send the enemy ships toward the player. We’ve already established a nice random timing mechanism when dropping asteroids on the scene. Let’s expand it by changing the section of our ‑update: method to call ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required