Moving the Plunger with a Touch

Now that we have two dedicated node instances—one for the ball and one for the plunger—we can start imagining how we want to control them with the player’s finger. We’ll use the same kind of mechanism we did back in Following the Finger Around, for Space Run. We need to add a dedicated property to remember the touch object when the finger is down at the top of the RCWMyScene.m file.

06-Physics/step10/PhysicsBall/RCWMyScene.m
 
@interface​ RCWMyScene ()
 
@property​ (nonatomic, weak) UITouch *plungerTouch;
 
@end

We’re declaring the property as weak because we don’t want to hold a strong reference to the touch. Since the touch-management system takes care of the touch objects, it will release them when the ...

Get Build iOS Games with Sprite Kit 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.