Object cocos2d中的捏手势,如何使用?

Object cocos2d中的捏手势,如何使用?,object,cocos2d-iphone,pinch,Object,Cocos2d Iphone,Pinch,我需要在我的cocos2d项目中使用两个或更多精灵实现一个简单的挤压手势。请您告诉我,我如何处理俯仰姿势 我需要这样的东西: -(void)handlePinchGesture:(UIPinchGestureRecognizer *)recognizer { if (recognizer.state != UIGestureRecognizerStateCancelled) { if (recognizer.numberOfTouches == 3)

我需要在我的cocos2d项目中使用两个或更多精灵实现一个简单的挤压手势。请您告诉我,我如何处理俯仰姿势

我需要这样的东西:

-(void)handlePinchGesture:(UIPinchGestureRecognizer *)recognizer 
{
    if (recognizer.state != UIGestureRecognizerStateCancelled) 
    {
         if (recognizer.numberOfTouches == 3) 
         {
             CGPoint firstPoint = [recognizer locationOfTouch:0 inView:recognizer.view];
             CGPoint secondPoint = [recognizer locationOfTouch:1 inView:recognizer.view];
             CGPoint thirdPoint = [recognizer locationOfTouch:2 inView:recognizer.view];
             CGPoint fourthPoint = [recognizer locationOfTouch:3 inView:recognizer.view];


             ball1.position=firstPoint;
             ball2.position=secondPoint;
             ball3.position=thirdPoint;
             ball4.position=fourthPoint;
         }
    }
}
这就是我所做的(我花了很多时间在谷歌上搜索)

在实施文件中

-(id)init
{
    self = [super init];
    self.isTouchEnabled=YES;


    if (self != nil) 
    {        

    }
    return self;   
}
//pinch recognising
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSSet *allUserTouches=[event allTouches];

    if(allUserTouches.count==2)
    {
        UITouch* touch1=[[allUserTouches allObjects] objectAtIndex:0];
        UITouch* touch2=[[allUserTouches allObjects] objectAtIndex:1];

        CGPoint touch1location=[touch1 locationInView:[touch1 view]];
        CGPoint touch2location=[touch2 locationInView:[touch2 view]];

        touch1location=[[CCDirector sharedDirector] convertToGL:touch1location];
        touch2location=[[CCDirector sharedDirector] convertToGL:touch2location];

        ball.position=touch1location;
        newBall.position=touch2location;

        float currentdist=ccpDistance(touch1location, touch2location);
        oldDist=currentdist;
    }
}

-(void)ccTouchesMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
    NSSet *allUserTouches=[event allTouches];

    if(allUserTouches.count==2)
    {
        UITouch* touch1=[[allUserTouches allObjects] objectAtIndex:0];
        UITouch* touch2=[[allUserTouches allObjects] objectAtIndex:1];

        CGPoint touch1location=[touch1 locationInView:[touch1 view]];
        CGPoint touch2location=[touch2 locationInView:[touch2 view]];

        touch1location=[[CCDirector sharedDirector] convertToGL:touch1location];
        touch2location=[[CCDirector sharedDirector] convertToGL:touch2location];

        float currentdist=ccpDistance(touch1location, touch2location);

        if (oldDist>=currentdist) 
        {
            //[spriteToZoom setScale:spriteToZoom.scale-fabs((oldDist-currentdist)/100)];
            [ball setPosition:touch1location];
            [newBall setPosition:touch2location];
            NSLog(@"pinch out");
        }
        else 
        {
            //[spriteToZoom setScale:spriteToZoom.scale+fabs((oldDist-currentdist)/100)];
            [ball setPosition:touch1location];
            [newBall setPosition:touch2location];

            NSLog(@"pinch in");
        }
    }
}
这就是我所做的(我花了很多时间在谷歌上搜索)

在实施文件中

-(id)init
{
    self = [super init];
    self.isTouchEnabled=YES;


    if (self != nil) 
    {        

    }
    return self;   
}
//pinch recognising
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSSet *allUserTouches=[event allTouches];

    if(allUserTouches.count==2)
    {
        UITouch* touch1=[[allUserTouches allObjects] objectAtIndex:0];
        UITouch* touch2=[[allUserTouches allObjects] objectAtIndex:1];

        CGPoint touch1location=[touch1 locationInView:[touch1 view]];
        CGPoint touch2location=[touch2 locationInView:[touch2 view]];

        touch1location=[[CCDirector sharedDirector] convertToGL:touch1location];
        touch2location=[[CCDirector sharedDirector] convertToGL:touch2location];

        ball.position=touch1location;
        newBall.position=touch2location;

        float currentdist=ccpDistance(touch1location, touch2location);
        oldDist=currentdist;
    }
}

-(void)ccTouchesMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
    NSSet *allUserTouches=[event allTouches];

    if(allUserTouches.count==2)
    {
        UITouch* touch1=[[allUserTouches allObjects] objectAtIndex:0];
        UITouch* touch2=[[allUserTouches allObjects] objectAtIndex:1];

        CGPoint touch1location=[touch1 locationInView:[touch1 view]];
        CGPoint touch2location=[touch2 locationInView:[touch2 view]];

        touch1location=[[CCDirector sharedDirector] convertToGL:touch1location];
        touch2location=[[CCDirector sharedDirector] convertToGL:touch2location];

        float currentdist=ccpDistance(touch1location, touch2location);

        if (oldDist>=currentdist) 
        {
            //[spriteToZoom setScale:spriteToZoom.scale-fabs((oldDist-currentdist)/100)];
            [ball setPosition:touch1location];
            [newBall setPosition:touch2location];
            NSLog(@"pinch out");
        }
        else 
        {
            //[spriteToZoom setScale:spriteToZoom.scale+fabs((oldDist-currentdist)/100)];
            [ball setPosition:touch1location];
            [newBall setPosition:touch2location];

            NSLog(@"pinch in");
        }
    }
}