Game Development Reference
In-Depth Information
Listing 8-14. PinchGestureController.h
@interface PinchGestureController : GameController{
Saucer* saucer;
float startRadius;
}
-(void)pinchGesture:(UIPinchGestureRecognizer*)sender;
@end
In Listing 8-14, we see the header file for the class PinchGestureController ; like the previous
example, it extends GameController . It also maintains a reference to the Saucer object, as well the
radius of the Saucer object at the beginning of a gesture. The task pinchGesture : is called by the
gesture recognizer. The implementation of this class will shed more light on how this example works,
starting with the doSetup task, as shown in Listing 8-15.
Listing 8-15. PinchGestureController (doSetup)
-(BOOL)doSetup{
if ([super doSetup]){
[self setGameAreaSize:CGSizeMake(320, 480)];
saucer=[Saucer saucer:self];
[self addActor:saucer];
UIPinchGestureRecognizer* pinchRecognizer = [[UIPinchGestureRecognizer alloc]
initWithTarget:self action:@selector(pinchGesture:)];
[actorsView addGestureRecognizer:pinchRecognizer];
return YES;
}
return NO;
}
In Listing 8-15, we have a very simple doSetup task for the class PinchGestureController . We simply
add a new saucer and set up a UIPinchGestureRecognizer to call pinchGesture : when a pinch
gesture is recognized. Let's take a look at how we respond to the gesture in the following section.
Responding to the Pinch Gesture
We have looked at how to register the pinch gesture recognizers. The implementation of
pinchGesture : is shown in Listing 8-16.
Listing 8-16. PinchGestureController (pinchGesture:)
-(void)pinchGesture:(UIPinchGestureRecognizer*)pinchRecognizer{
if (pinchRecognizer.state == UIGestureRecognizerStateBegan){
startRadius=[saucer radius];
[saucer setAnimationPaused:YES];
} else if (pinchRecognizer.state == UIGestureRecognizerStateChanged){
 
Search WWH ::




Custom Search