cocos2d中的曲线

时间:2011-11-28 09:23:03

标签: iphone cocoa-touch cocoa cocos2d-iphone

我必须在cocos2d中开发曲线。曲线是手指旋转的模拟器,这是根据触摸位置弯曲的一些顶级烈酒。 我有一个50精神点数组的数组。如果我们移动第一个精神(在代码BG_Sprite3中),想要设置第1,第2,第3,......第50个精神位置(在代码BG_Sprite2中)和旋转按照触摸位置。如果我们移动得更深(如果没有)那么BG_Sprite2的旋转和位置也会改变。就像手指弯曲和手指旋转一样。

这是我的代码..代码工作。但没有得到BG_Sprite2的弯曲旋转。

       -(id) init
       {
       if( (self=[super init]))
            {
      aPoints = [[NSMutableArray alloc]init]; 
     [self removeChild:BG_Sprite2 cleanup:YES];   
    int m=100,n=80;
    for(int i=0;i<25;i++)
    {

        BG_Sprite2 = [CCSprite spriteWithFile:@"nodeConnectorWhite.png"];
        BG_Sprite2.position = ccp(m,n);
         m=m+5;
        n=n+5;
        BG_Sprite2.rotation=135;
        [self addChild:BG_Sprite2];
        [aPoints addObject:[NSValue valueWithCGPoint:ccp(m,n)]];
    }    
    [self removeChild:BG_Sprite3 cleanup:YES];   
    BG_Sprite3 = [CCSprite spriteWithFile: @"connection_green.png"];//This is first spirit    
 BG_Sprite3.position=ccp(235, 215);
    [BG_Sprite3 setRotation:135];

     [self addChild:BG_Sprite3];

            }
         }

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

             NSMutableArray *apointsarray = [[NSMutableArray alloc]init];  
             CGPoint movedtouchLocation = [touch locationInView: [touch view]];   

            movedtouchLocation = [[CCDirector sharedDirector] convertToGL:                 movedtouchLocation];

int xDiff= movedtouchLocation.x-225;//angle between first spirit and touch location
int yDiff= movedtouchLocation.y-205;
        for(int i=0;i<[aPoints  count];i++)
    {           
         float angle2 = atan2f(xDiff, yDiff); 
          angle2 = CC_RADIANS_TO_DEGREES(angle2); // convert to degrees
        angle2 -= 90; // rotate
        angle2 *= -1; // clockwise
          BG_Sprite2 = [CCSprite spriteWithFile:@"nodeConnectorWhite.png"];
             BG_Sprite2.position =movedtouchLocation;
            [BG_Sprite2 setRotation:angle2];
        [self addChild:BG_Sprite2];

           }

     }

0 个答案:

没有答案