cocos2d之CCBezierBy,CCBezierTo

 

http://blog.csdn.net/we000636/article/details/8616355,这篇文章写得很详细,我在此基础上写了个例子,代码如下:

 

void MyActionBezierLayer::initLayer() {
	CCSize size = CCDirector::sharedDirector()->getWinSize();
	CCSprite *pSpriteMove = CCSprite::create("face.jpg");
	pSpriteMove->setPosition(ccp(50, 100));
	this->addChild(pSpriteMove, 1);
	ccBezierConfig  beziercofig;
	beziercofig.controlPoint_1 = ccp(200, 300);
	beziercofig.controlPoint_2 = ccp( 100, 100);
	beziercofig.endPosition = ccp(100, 100);

	CCActionInterval *forward = CCBezierBy::create(3, beziercofig);
	CCActionInterval *last = forward->reverse();
	CCAction*  rep = CCRepeatForever::create(CCSequence::create( forward, last, NULL));
	pSpriteMove->runAction(rep);

}

这里用到了CCRepeatForever,让该动作无限次重复,它继承的是CCActionInterval。

下面是里利用CCBezierTo创建一个贝塞尔曲线运动

void MyActionCCBezierToLayer::initLayer() {
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    ccBezierConfig bezierTo;
    bezierTo.controlPoint_1 = ccp(100, 200);
    bezierTo.controlPoint_2 = ccp(500, 400);
    bezierTo.endPosition = ccp(200, 200);
    CCSprite *spriteMove = CCSprite::create("close.png");
    spriteMove->setPosition(ccp(300, 300));
    this->addChild(spriteMove, 1);

    CCActionInterval *forward = CCBezierTo::create(2, bezierTo);
    CCActionInterval *last = forward->reverse();
    CCAction *action = CCRepeatForever::create(dynamic_cast<CCActionInterval *>(CCSequence::create(forward, last, NULL)) );
    spriteMove->runAction(action);
}


你可能感兴趣的:(cocos2d之CCBezierBy,CCBezierTo)