O'Reilly logo

Cocos2d Cross-Platform Game Development Cookbook - Second Edition by Siddharth Shekar

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

Adding panning

We can pan the image by moving two fingers placed on the screen at the same distance and not rotating either of them.

Getting ready

To pan, no additional work is required.

How to do it…

In the init function, we will create a variable for the pan gesture recognizer and set the function call as follows:

// ** Pan ** //
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizeralloc] initWithTarget:self action:@selector(handlePanFrom:)] ;
[[UIApplicationsharedApplication].delegate.windowaddGestureRecognizer:panGestureRecognizer];

Next, we will add the function to handle the pan gesture:

- (void)handlePanFrom:(UIPanGestureRecognizer *)recognizer { if (recognizer.state == UIGestureRecognizerStateBegan) { // nothing here } else ...

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