Apple's touch devices popularized using two fingers to zoom in and out and this method remains the most popular way to zoom on any widely available touch screen device. In this recipe, we will see how to zoom a scene in and out by pinching.
Please refer to the project RecipeCollection01 for full working code of this recipe. Also note that the arrow effect shown in the previous screenshot has been omitted from the following code.
Execute the following code:
#import "IphoneCube.h" @implementation Ch2_PinchZooming -(CCLayer*) runRecipe { //Enable touching self.isTouchEnabled = YES; //Set initial variables arrowsIn = NO; cameraZoom = 1.0f; lastMultiTouchZoomDistance = 0.0f; //Init background bg = [CCSprite spriteWithFile:@"dracula_castle.jpg"]; bg.position = ccp(240,160); [self addChild:bg]; //Set initial zoom [self setCameraZoom:1]; return self; } /* Check for HUD input */ -(bool) hudPressedWithPoint:(CGPoint)point { ...