cocos2d-x动画整理(原文)

欢迎转载:注明出处:http://www.cnblogs.com/jiackyan/admin/EditPosts.aspx?opt=1

//随便试了试,还有一些 都是这些动画 互相融合在一起的动画,举一反三 就OK



//move 动画 移动动画



    CCSize s = CCDirector::sharedDirector()->getWinSize();



    CCSprite*sprite1=CCSprite::create("52design.com_kr_001.png");



    sprite1->cocos2d::CCNode::setPosition(200, 200);



    sprite1->setScale(0.4);



    this->addChild(sprite1);



    CCActionInterval*  actionBy = CCMoveBy::create(2, ccp(sprite1->getPositionX(),sprite1->getPositionY()));//开始位置



    CCActionInterval*  actionTo = CCMoveTo::create(2, ccp(s.width-40, s.height-40));//结束位置



    CCActionInterval*  actionByBack = actionBy->reverse();



    sprite1->runAction( CCSequence::create(actionBy, actionByBack, NULL));//折回



//    sprite1->runAction(actionTo);



//      sprite1->runAction(CCMoveTo::create(1, ccp(40,40)));



//缩放动画 Scale比例



 



    CCActionInterval*  actionTo = CCScaleTo::create(2.0f, 0.5f);



    CCActionInterval*  actionBy = CCScaleBy::create(2.0f, 1.0f, 10.0f);



    CCActionInterval*  actionBy2 = CCScaleBy::create(2.0f, 5.0f, 1.0f);



//    sprite1->runAction( actionTo);



//    sprite1->runAction( CCSequence::create(actionBy, actionBy->reverse(), NULL));



    sprite1->runAction( CCSequence::create(actionBy2, actionBy2->reverse(), NULL));



//旋转动画



 



  CCActionInterval*  actionBy = CCRotateBy::create(2 ,  360);



    CCActionInterval*  actionByBack = actionBy->reverse();



    sprite1->runAction( CCSequence::create(actionBy, actionByBack, NULL));



 



//旋转并扩大



 



 CCActionInterval *actionTo = CCSkewTo::create(2, 37.2f, -37.2f);



    CCActionInterval *actionToBack = CCSkewTo::create(2, 0, 0);



sprite1->runAction(CCSequence::create(actionBy, actionByBack, NULL));



//jump 动画



 



 CCActionInterval*  actionBy = CCJumpBy::create(2, ccp(300,0), 50, 4);//4分几次弹跳过去



  CCActionInterval*  actionByBack = actionBy->reverse();



 sprite1->runAction( CCSequence::create(actionBy, actionByBack, NULL));



//贝瑟尔曲线动画



 



ccBezierConfig bezier;



    bezier.controlPoint_1 = ccp(0, s.height/2);



    bezier.controlPoint_2 = ccp(300, -s.height/2);



    bezier.endPosition = ccp(300,100);



 



    CCActionInterval*  bezierForward = CCBezierBy::create(3, bezier);



    CCActionInterval*  bezierBack = bezierForward->reverse();    



    CCAction*  rep = CCRepeatForever::create((CCActionInterval*)CCSequence::create( bezierForward, bezierBack, NULL));



 sprite1->setPosition(ccp(400,160));



 



//闪烁动画



 



CCActionInterval*  action1 = CCBlink::create(2, 10);



 sprite1->runAction( action1);



//慢慢变黑



 



 CCActionInterval*  action1 = CCFadeIn::create(1.0f);



    CCActionInterval*  action1Back = action1->reverse();



 sprite1->runAction( CCSequence::create( action1, action1Back, NULL));



//颜色动画



 



CCActionInterval*  action2 = CCTintBy::create(2, -127, -255, -127);



    CCActionInterval*  action2Back = action2->reverse();



 sprite1->runAction( CCSequence::create( action2, action2Back, NULL));



 



//动画完成回调



 



CCFiniteTimeAction*  action = CCSequence::create(



        CCPlace::create(ccp(200,200)),



        CCShow::create(),



        CCMoveBy::create(1, ccp(100,0)),



        CCCallFunc::create(this, callfunc_selector(ActionSequence2::callback1)),



        CCCallFuncN::create(this, callfuncN_selector(ActionSequence2::callback2)),



        CCCallFuncND::create(this, callfuncND_selector(ActionSequence2::callback3), (void*)0xbebabeba),



        NULL);



 



    sprite1->runAction(action);



//间歇性动画 

  CCActionInterval*  move = CCMoveBy::create(1, ccp(150,0));



    CCFiniteTimeAction*  action = CCSequence::create( move, CCDelayTime::create(2), move, NULL);//休息两秒再移动



 



    sprite1->runAction(action);



 



 



  CCActionInterval*  a1 = CCMoveBy::create(1, ccp(150,0));



    CCActionInterval*  action1 = CCRepeat::create(



        CCSequence::create( CCPlace::create(ccp(60,60)), a1, NULL) , 



        3); 



    CCAction*  action2 = CCRepeatForever::create(



        (CCActionInterval*)(CCSequence::create((CCActionInterval*)(a1->copy()->autorelease()), a1->reverse(), NULL))



        );



 



    sprite1->runAction(action1);//连续播放3遍



    sprite2->runAction(action2);//一直播

 

你可能感兴趣的:(cocos2d-x)