Game Development Reference
In-Depth Information
Listing 8-21. RotationGestureController.m (doSetup)
-(BOOL)doSetup{
if ([super doSetup]){
[self setGameAreaSize:CGSizeMake(320, 480)];
viper=[Viper viper:self];
[self addActor:viper];
UIRotationGestureRecognizer* rotationRecognizer=[[UIRotationGestureRecognizer alloc]
initWithTarget:self action:@selector(rotationGesture:)];
[actorsView addGestureRecognizer:rotationRecognizer];
return YES;
}
return NO;
doSetup task of RotationGestureController is very simple.
UIRotationGestureRecognizer . There should be no
rotationGesture : will be called as the object
detects touch events that can be interpreted as a rotation gesture. Let's take a
rotationGesture :, as shown in Listing 8-22.
RotationGestureController.m (rotationGesture:)
-(void)rotationGesture:(UIRotationGestureRecognizer*)rotationRecognizer{
if ([rotationRecognizer state] == UIGestureRecognizerStateBegan){
startRotation=[viper rotation];
} else if ([rotationRecognizer state] == UIGestureRecognizerStateChanged){
float rotation=[rotationRecognizer rotation];
float finalRotation=startRotation+rotation*2.0;
if (finalRotation>[viper rotation]){
[viper setState:VPR_STATE_CLOCKWISE];
} else {
[viper setState:VPR_STATE_COUNTER_CLOCKWISE];
}
[viper setRotation: finalRotation];
} else if ([rotationRecognizer state] == UIGestureRecognizerStateEnded){
[viper setState:VPR_STATE_STOPPED];
} else if ([rotationRecognizer state] == UIGestureRecognizerStateCancelled){
[viper setState:VPR_STATE_STOPPED];
[viper setRotation:startRotation];
}
}
 
Search WWH ::




Custom Search