Мне нужно разработать изогнутую линию в cocos2d. Кривые похожи на вращение пальцев, то есть некоторые из верхних духов, изогнутых в зависимости от местоположения касания.
у меня есть массив из 50 точек-точек. Если мы двигаем первый уровень (в коде BG_Sprite3), хотим установить 1-ю, 2-ю, 3-ю, .... 50-ую позицию духа (в коде BG_Sprite2) и вращение в соответствии с касанием. Если мы двигайтесь глубже (ЕСЛИ Y МЕНЬШЕ), затем вращение и положение 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];
}
}