I have a game in which the player moves around a sprite by tapping on various sections of the screen (left, right, up, down). So far, each tap moves the sprite one tile (I use a tile system for movement, among other things), so to move the sprite a long distance the player has to tap in the direction they want for a while. Is there a way to combine a tap gesture recognizer and a long hold gesture recognizer so that if the player taps once, the sprite moves one tile in the direction tapped and if the player holds, the player moves in that direction until the player stops holding?
Here's my code for a single direction just as an example of what I have:
-(void)handleRightTap {
self.player.direction = RIGHT;
float currentSpriteX = self.playerSprite.center.x;
float currentSpriteY = self.playerSprite.center.y;
//If the animation is not already happening and the destination is accessible...
if(!self.isAnimating && self.toTile.isWalkable) {
self.isAnimating = YES;
//If the player has reached the edge of the screen...
if([self checkIfPlayerHasReachedEndForPoint:toPoint]) {
self.isAnimating = NO;
return;
}
CABasicAnimation *moveAnimation = [CABasicAnimation animation];
moveAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(currentSpriteX + TILE_WIDTH, currentSpriteY)];
[moveAnimation setDelegate:self];
[moveAnimation setFillMode:kCAFillModeForwards];
[moveAnimation setRemovedOnCompletion:NO];
[moveAnimation setDuration:MOVE_ANIMATION_DURATION];
[self.playerSprite.layer addAnimation:moveAnimation forKey:@"position"];
}
}