I'm trying to make a sort of free runner game. I make the character jump by setting an integer to 30 or so every time the screen is tapped, and moving the character up the screen using CGPointMake()
. Then I have a timer start when the player taps the screen which pulls the character down until he's reached a certain point (y=260). Then the timer invalidates and the character's downward movement stops.
This goes on and on and works perfectly well until you tap on the screen before the character reaches y=260. This makes him jerk up and come speeding down very fast and he doesn't stop at y=260 like he should. Here's the code that I think is causing the problem:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
playerMoving = 33;
gravity = [NSTimer scheduledTimerWithTimeInterval:.2
target:self
selector:@selector(playerJump)
userInfo:nil
repeats:YES];
}
Every time I double tap on the screen the timer gets activated again, even though it is already activated, and this is what I think is causing the problem.
Is there any way to not let the player tap on the screen a second time until the character has reached y=260 (so basically the player won't be able to double jump)?