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

Making the Ship Glide

As our game is now, we have a mechanical problem with our ship. It only moves when a touch begins on the screen, and we want it to move toward where the finger drags around on the screen. Because we get all the standard touch events from iOS, we could copy the same code into ‑touchesMoved:withEvent: and update the ship’s position property there, but there’s a simpler way with Sprite Kit.

Let’s start with a property that keeps track of the touch that we received until the touch ends. Add this class extension to the top of the RCWMyScene.m file above the @implementation definition:

01-SpriteIntro/step04/SpaceRun/RCWMyScene.m
 
@interface​ RCWMyScene ()
 
@property​ (nonatomic, weak) UITouch *shipTouch;
 
@end

We’re declaring ...

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