1

I'm trying to move a sprite around using UITouch and i need to be in multi touch mode because i have a button i also need to hit while i'm moving my sprite around.

The issue is when i miss the button and i hit the screen with my other finger the second finger becomes the touches begins which cause my sprite to jump positions. Any work around. I tried putting by button in its own class but that didn't help. The reason why I'm not just putting all the code in touches moved is because I'm calculating the offset from the touches began.

-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    NSSet *allTouches = [event allTouches];
    switch ([allTouches count]) {
        case 1:{
            NSLog(@"moving touch 1");}break;

So now what is happening is when i move my finger across the screen it detects moving 1 but once i put on the second finger it stops moving 1 i don't want it to stop moving 1

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
michael
  • 11
  • 2

2 Answers2

0

In your -touchesBegan: method, are you testing the point of the touch to see if it’s inside the image?

Jeff Kelley
  • 19,021
  • 6
  • 70
  • 80
0

put a condition on both button touch and don't include any else case there that will be all to avoid other touches.

Like :

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    NSSet *allTouches = [event allTouches];

    switch ([allTouches count]) {
        case 1: {
            CGPoint pos = [[[allTouches allObjects] objectAtIndex:0] locationInView:self];
            // code here for single touch.


        } break;
        case 2: {
            //get out two fingers
            UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
            UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];
            // code here for multi touch

        } break;

    }


}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    NSSet *allTouches = [event allTouches];

    switch ([allTouches count])
    {
        case 1: { //Move
            //Single touch


        } break;
        case 2: { //Zoom
            //multi touch

            UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
            UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];

            // Code according to you


        } break;

    } 

}

Hope this will help.

Haroon
  • 697
  • 1
  • 9
  • 24
  • testing it out now thanx for the response – michael Jan 19 '12 at 14:53
  • This was a big help but did not fix my problem please check my code up top – michael Jan 19 '12 at 15:49
  • What you have to do is, you have to repeat the code in case 2 too. So that if you touch two fingers, the code switch to second case but its will find case 1 code too.It will be better if you a make a method of case 1. – Haroon Jan 20 '12 at 13:11
  • I'm trying to just ignore the Second touch all together unless I hit my button – michael Jan 20 '12 at 17:20