enough is enough.
like the title says, I'm in a bit of a pickle.
so here's the outline of my problem. I have this ship right. It rests in the center bottom of the screen (240,0). When the user touches to the right at a point greater than 240 the ship moves right. And left if the user touches at a point less than 240. HOWEVER this is great when there's only one finger on the screen at a time. I need it to where if the user touches right, doesn't lift their finger, then touches left (OH CRAP THERE'S TWO FINGERS ON THE SCREEN) the ship keeps moving right until they lift their right finger, then suddenly the ship moves left towards the second touch.
I'm using timers to add/subtract a number from the current x coordinate to get it to move.
This is what I have in a nutshell: (Don't laugh or hate I'm a noob)
-(void)moveShipLeft:(id)sender {
shipView.center = CGPointMake(shipView.center.x - 2, 320 - (shipView.image.size.height / 2));
}
-(void)moveShipRight:(id)sender {
shipView.center = CGPointMake(shipView.center.x + 2, 320 - (shipView.image.size.height / 2));
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
if (240 < location.x){rightTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(moveShipRight:) userInfo:nil repeats:YES];}
if (240 > location.x){leftTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(moveShipLeft:) userInfo:nil repeats:YES];}
[shipView setCenter:shipView.center];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if (rightTimer != nil) //Kill the timer that goes right upon touch removal
[rightTimer invalidate];
rightTimer = nil;
if (leftTimer != nil) //Kill the timer that goes left on touch removal
[leftTimer invalidate];
leftTimer = nil;
}
I'm trying to fully replicate the controls for the game "Radiant" if its any help. I will seriously love you forever if you help.
Just to clarify, I want this to happen:
- user touches the right side of screen
- ship moves right
- user touches left side of screen with second finger
- while the ship is still moving right because the user hasn't lifted their first touch, the user then lifts the first touch
- THEN the ship instantly changes course to move left towards the second touch
right now I have multi touch enabled, so now it works like this:
- user touches the right side of screen
- ship moves right
- user touches left side of screen with second finger
- ship moves left then user lift first touch
- ship is stopped in its tracks even though the user hasn't lifted the second touch