Game Development Reference
In-Depth Information
Listing 8-17. PanGestureController.h
@interface PanGestureController : GameController{
NSMutableArray* asteroids;
int asteroidIndex;
CGPoint startCenter;
}
@property (nonatomic) float minYValue;
@property (nonatomic) float maxYValue;
-(void)panGesture:(UIPanGestureRecognizer*)panRecognizer;
@end
PanGestureController , which again extends
. We keep an ordered list of the asteroids in the NSMutableArray asteroids. We also
int asteroidIndex and
CGPoint startCenter . The properties minYValue and maxYValue specify how far each Asteroid
panGesture : is called by the UIPanGestureRecognizer when a
, so let's start with the doSetup tasks, as shown in Listing 8-18.
PanGestureController.m (doSetup)
if ([super doSetup]){
[self setGameAreaSize:CGSizeMake(320, 480)];
[self setMinYValue:72.0f];
[self setMaxYValue:480-[self minYValue]];
asteroids=[NSMutableArray new];
for (int i=0;i<3;i++){
Asteroid* asteroid=[Asteroid asteroid:self];
[[asteroid behaviors] removeAllObjects];
[self addActor:asteroid];
[asteroids addObject:asteroid];
CGPoint center=CGPointMake(i*320.0/3.0+320.0/6.0, [self minYValue]);
[asteroid setCenter:center];
}
UIPanGestureRecognizer* panRecognizer=[[UIPanGestureRecognizer alloc] initWithTarget:self
action:@selector(panGesture:)];
[panRecognizer setMinimumNumberOfTouches:1];
[actorsView addGestureRecognizer:panRecognizer];
return YES;
}
return NO;
}
 
Search WWH ::




Custom Search