贝塞尔曲线运动

时间:2012-10-24 17:20:41

标签: iphone cocos2d-iphone bezier

我想使用触摸将一个三维贝塞尔曲线从源点移动到目标点,就像线条绘制一样,但在我的情况下不是通过触摸,或者当一个场景被调用时,你可以说只是通过绘制方法或更新方法(不是精灵运动)沿贝松曲线)。

我的代码是 - >在这里,我只需要一个精灵(一个小图像线),在曲线点的帮助下,我只做曲线路径。(当我调用场景然后直接弯曲路径显示)

但我希望从源点到目标点进行正确的曲线移动动画。

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]]];

}

我也尝试过使用这样的draw方法:

-(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);




    }


}

但这里也有同样的问题,当我调用场景时,直接显示三次曲线。

请帮我解决这个问题,抱歉我的英文不好, 任何帮助将不胜感激 感谢

0 个答案:

没有答案