It worked!! (the only change I made was to remove '.frame' from 'lowerFrame' in the 'CGRectIntersectsRect' statement)
I have written this code to detect swipes and move the character left and right:
Code:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
character.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"character.png"],
[UIImage imageNamed:@"character2.png"], nil];
character.animationDuration = 0.5;
character.animationRepeatCount = 1;
[character startAnimating];
[self.view addSubview:character];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
startTouchPosition = [touch locationInView:self];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self];
if (fabsf(startTouchPosition.x - currentTouchPosition.x) >= HORIZ_SWIPE_DRAG_MAX &&
fabsf(startTouchPosition.y - currentTouchPosition.y) <= VERT_SWIPE_DRAG_MIN)
{
if (startTouchPosition.y < currentTouchPosition.y)
[self characterJump:touches withEvent:event]; }
CGPoint location = [touch locationInView:touch.view];
CGPoint xLocation = CGPointMake(location.x,character.center.y);
character.center = xLocation;
}
Xcode returns a ton of errors when I try to compile it.. but I'm not sure why?? I also want my character to jump when a swipe is detected, but I don't want to just animate him because then he wont react to landing on a block (I want him to always be travelling down the screen, unless he is on a block or in a jump).
Sorry if this is a lot of questions :S
Cam