# How do I rotate a sprite with ccbezierTo in cocos2d-x?

In cocos2d-x, I move a sprite with ccbezierTo like this:

// use for ccbezierTo
bezier.controlPoint_1 = ccp(m_fish->getPositionX() + 200, visibleSize.height/2 + 300);
bezier.controlPoint_2 = ccp(m_fish->getPositionX() + 400, visibleSize.height/2 - 300);
bezier.endPosition = ccp(m_fish->getPositionX() + 600,visibleSize.height/2);

bezier1.controlPoint_1 = ccp(m_fish->getPositionX() + 800, visibleSize.height/2 + 300);
bezier1.controlPoint_2 = ccp(m_fish->getPositionX() + 1000, visibleSize.height/2 - 300);
bezier1.endPosition = ccp(m_fish->getPositionX() + 1200,visibleSize.height/2);

bezierForward = CCBezierTo::create(6, bezier);
nextBezier = CCBezierTo::create (6,bezier1);

m_fish->runAction(CCSequence::create( bezierForward, nextBezier, NULL));


How can I make my sprite rotate while moving it with CCBezierTo?

• Jun 4 '14 at 12:32
• Thanks i solved, i use this code: CGPoint oldpos = [[self target] position]; [super update:time]; CGPoint newpos = [[self target] position]; float angle = atan2(-newpos.y + oldpos.y, newpos.x - oldpos.x) * 180 / M_PI; angle += 90; // my sprites start pointing up [[self target] setRotation:angle]; Jun 5 '14 at 3:03
• Can you write it as an answer and mark it "accepted" please? It will be easier for people having the same problem to find an answer Jun 5 '14 at 4:37
• Sure, i use this link gamedev.stackexchange.com/questions/20527/… Jun 5 '14 at 8:23
• I mean, can you write an answer explaining how you solved it ? Not only a comment. You would then be able to mark your answer as "accepted" so people would know it worked for you. Jun 5 '14 at 9:42

 CGPoint oldpos = [[self target] position];