Rotate a Sprite on a bezier path with touch - Cocos2D/Box2D

前端 未结 2 1893
说谎
说谎 2021-01-14 06:21

I have an arrow that I rotate with touch. I was wondering if it was possible to rotate the arrow on a curved line? I\'ve done some research and I think it is called a bezier

2条回答
  •  青春惊慌失措
    2021-01-14 07:07

    Never tried but i think it's possible, basically what you want to do is when the user touch the screen the arrow move to the touch location on a curve line and the arrow rotate on the curve ?

    first you need to make the arrow rotate and then perform the bezier action

    //on touch
    CGSize s = [[CCDirector sharedDirector] winSize];
    
    //rotate action we make the arrow rotate forever
    id actionBy = [CCRotateBy actionWithDuration:2  angle: 360];
    [arrow runAction: [CCRepeatForever actionWithAction:actionBy]];
    
    //bezier action
    ccBezierConfig bezier;
    bezier.controlPoint_1 = ccp(0, s.height/2);
    bezier.controlPoint_2 = ccp(300, -s.height/2);
    bezier.endPosition = ccp(300,100);
    
    id bezierForward = [CCBezierBy actionWithDuration:3 bezier:bezier];
    id action = [CCCallFunc actionWithTarget:self selector:@selector(endAction)];
    [arrow runAction:[CCSequence actions:bezierForward, action]];
    
    //write a method endAction
     [arrow stopAllActions];
    

提交回复
热议问题