http://www.cocoachina.com/bbs/read.php?tid=84995

需求:一个打飞机2、如果采取变种的办法,人为的分成n个曲线动作,放在动作序列中,再运行动作序列,怎样才能让各个动作之间没有停顿的现象。

 

//startPos----varStartAndEnd-----.-----.----.--.------.----varStartAndEnd----destPos
-(CCSequence*)makeBeizPoses:(CGPoint)startPos destPos:(CGPoint)destPos routeCount:(int)routeCount varStartAndEnd:(int)varStartAndEnd{
    float beiZposesX_int[FLY_ROUTE_MAX] = {0};
    float beiZposesY_int[FLY_ROUTE_MAX] = {0};
//NSArray* beiZposesX,*beiZposesY;
    NSArray* beiZposesX = [[NSArray alloc]init];
    NSArray* beiZposesY = [[NSArray alloc]init];
    int plugPoint = routeCount - 1;
    float startP,endP;
    startP = startPos.x + varStartAndEnd;
    endP = destPos.x - varStartAndEnd;
    if(plugPoint >= 1)
    {
        beiZposesX = [self pickUniqueNumbers:plugPoint min:startP max:endP];
        beiZposesY = [self pickUniqueNumbers:plugPoint min:FLY_SCAPE_LOW max:FLY_SCAPE_TOP];
    }

    float changeTemp = 0;

//SET beiZposesX_int
    beiZposesX_int[0] = startPos.x;
    beiZposesX_int[routeCount] = destPos.x;
    beiZposesY_int[0] = startPos.y;
    beiZposesY_int[routeCount] = destPos.y;

    for (int i = 0; i < [beiZposesX count]; i ++) {
        beiZposesX_int[i+1] = [[beiZposesX objectAtIndex:i]floatValue];
    }
//SET beiZposesY_int
    int coutY = [beiZposesY count];
NSLog(@"coutY is:%d",coutY);
    for (int i = 0; i < [beiZposesY count]; i ++) {
        beiZposesY_int[i+1] = [[beiZposesY objectAtIndex:i]floatValue];
    }
    if(startPos.x < destPos.x)
    {
        for (int i = 0; i < routeCount; i ++) 
        {
            for (int j = 0; (j+1) <= (routeCount - i); j ++) 
                if (beiZposesX_int[j + 1] < beiZposesX_int[j] )
                {
                    changeTemp = beiZposesX_int[j + 1];
                    beiZposesX_int[j + 1] = beiZposesX_int[j];
                    beiZposesX_int[j] = changeTemp;
                }
        }
    }
    else
    {
        for (int i = 0; i < routeCount; i ++) 
        {
            for (int j = 0; (j+1) <= (routeCount - i); j ++) 
                if (beiZposesX_int[j + 1] > beiZposesX_int[j] )
                {
                    changeTemp = beiZposesX_int[j + 1];
                    beiZposesX_int[j + 1] = beiZposesX_int[j];
                    beiZposesX_int[j] = changeTemp;
                }

        }
    }

    CGPoint beizPoses[routeCount + 1];
    for(int index = 0;index <= routeCount;index++)
        beizPoses[index] = CGPointMake(beiZposesX_int[index], beiZposesY_int[index]);

    float useTime;
    id actionCallFunc = [CCCallFunc actionWithTarget:self selector:@selector(disAppear)];
    CCSequence* seqFly;
NSMutableArray* actionArray = [NSMutableArray arrayWithCapacity:routeCount];
ccBezierConfig bezier;
    CCBezierTo *flymove;
    for(int i = 0;i < routeCount;i ++)
    {
        bezier.controlPoint_1 = beizPoses;//start point
        bezier.endPosition = beizPoses[i + 1];//end ponit
        bezier.controlPoint_2 = [self makeBezCtrlPos:bezier.controlPoint_1 endPos:bezier.endPosition]; //control ponit

        useTime = [self makeFlyTime:bezier.controlPoint_1   endPos:bezier.endPosition]; 
        flymove = [CCBezierTo actionWithDuration:useTime bezier:bezier];
        [actionArray addObject:flymove];

    }
    [actionArray addObject:actionCallFunc];
    seqFly = [CCSequence actionsWithArray:actionArray];
//[beiZposesX release];
//[beiZposesY release];
    return seqFly;
}





代码如下:

相关文章: