////////////Template code //////////// Chunk 1 static const CGFloat kTrackPointsPerSecond = 1000; -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { const CGRect touchRegion = CGRectMake(0, 0, self.size.width, self.size.height * 0.3); for (UITouch *touch in touches) { CGPoint p = [touch locationInNode:self]; if (CGRectContainsPoint(touchRegion, p)) { self.motivatingTouch = touch; } } [self trackPaddlesToMotivatingTouches]; } -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [self trackPaddlesToMotivatingTouches]; } -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { if ([touches containsObject:self.motivatingTouch]) self.motivatingTouch = nil; } -(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { if ([touches containsObject:self.motivatingTouch]) self.motivatingTouch = nil; } - (void)trackPaddlesToMotivatingTouches { SKNode *node = [self childNodeWithName:@"Paddle"]; UITouch *touch = self.motivatingTouch; if (!touch) return; CGFloat xPos = [touch locationInNode:self].x; NSTimeInterval duration = ABS(xPos - node.position.x) / kTrackPointsPerSecond; [node runAction:[SKAction moveToX:xPos duration:duration]]; }