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 pinch/zoom controls

Pinch/zoom is a two-finger gesture in which if you place two fingers on the screen and bring the fingers closer, the image will be scaled down in size, and if you move the fingers apart, the image is enlarged.

Getting ready

For this, we need an image to work with; so, import the Bg image from the first chapter to work with. Make the sprite a global variable as we will need to access it in another function.

So, in the MainScene.h file, we will add an instance of CCSprite as CCSprite* backgroundImage;.

Also, we will add a global float called currentScale to track the current scale value of the background image.

Next, in the init function, we will initialize the variable, as follows:

backgroundImage = [CCSpritespriteWithImageNamed:@"Bg.png"]; ...

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