1

I want to move a cubic bezier curve from source point to destination point like line draw using touches but in my case not by touches, or u can say just by draw method or update method when a scene called(not a sprite movement along bezier curve).

My Code is-> Here i just take one sprite(one small image line) and with the help of curve points i just make curve path.(when i called scene then direct curved path showing)

but I want proper curve movement animation from source point to destination point.

curvePoints=[[NSMutableArray alloc]init];




for (CGFloat t = 0.0; t <= 1.00001; t += 0.005)
        {
        CGPoint point = CGPointMake(
                                    _bezierPoint(t,237, 320,423,609),
                                    _bezierPoint(t, 319, 461,529,534));

        CCSprite*path=[CCSprite spriteWithFile:@"path.png"];

       [self addChild:path];          
        [path setPosition:[[CCDirector sharedDirector]convertToGL:point]];
        [curvePoints addObject:[NSValue valueWithCGPoint:[[CCDirector sharedDirector]convertToGL:point]]];

}

I have also tried using the draw method like this:

-(void)draw{
    CGSize s = [[CCDirector sharedDirector] winSize];


    CGPoint point1 = CGPointMake(237, 705);


    CGPoint point2 = CGPointMake(320, 563);


    CGPoint point3 = CGPointMake(423, 495);


    CGPoint point4 = CGPointMake(609, 490);


    [curvePoints addObject:NSStringFromCGPoint(point1)];



    [curvePoints addObject:NSStringFromCGPoint(point2)];



    [curvePoints addObject:NSStringFromCGPoint(point3)];



    [curvePoints addObject:NSStringFromCGPoint(point4)];



    glEnable(GL_LINE_SMOOTH);


    for(int i = 0; i < [curvePoints count]; i+=2)
    {
        CGPoint origin = CGPointFromString([curvePoints objectAtIndex:i]);


        CGPoint control1 = CGPointFromString([curvePoints objectAtIndex:i+1]);



        CGPoint control2 = CGPointFromString([curvePoints objectAtIndex:i+1]);


        CGPoint destination = CGPointFromString([curvePoints objectAtIndex:i+1]);



        ccDrawCubicBezier(origin, control1, control2, destination, 100);




    }


}

but here also same problem,when I called scene,direct cubic curve showing.

Please help me out of this problem,sorry for my bad English, any help will be appreciated Thanks

4

0 回答 0