--- Detailed explanation of CCAction (I owe you a few days), ccaction

Source: Internet
Author: User

--- Detailed explanation of CCAction (I owe you a few days), ccaction

A few days ago, I was so lazy that I had to go to class during the day, and then I almost fell asleep when I came back at night. So I didn't get anything to do, so I finally got started to study hard today. Today, CCAction includes CCAction, CCFiniteTimeAction, CCSpeed, CCFollow,

Let's get started ,:



CCAction is divided into three types: CCFiniteTimeAction, CCSpeed, and CCFollow.



CCFiniteTimeAction is divided into two types. The CCAction should be written as CCFiniteTimeAction,

CCFiniteTimeAction includes CCActionInstant (instantaneous action) and CCActionInterval (delayed action)





The instantaneous actions include the above actions, which are completed in an instant. We cannot see the transformation process. It should be too fast for him. You may ask why CCPlace and setPosition are not both similar. In fact, they can be encapsulated into an order by using CCPlace as an action, isn't that the difference between CCPlace and setPosition.

Sample Code:

CCFlipY *flipx = CCFlipY::create(true);CCHide *hide = CCHide::create();CCToggleVisibility *togglevis = CCToggleVisibility::create();CCPlace *place = CCPlace::create(ccp(200, 200));


Simple usage

The above several relatively difficult to understand are false actions CCCallFunc, so let's talk about this in detail. A false action means no action. In fact, it is only a callback.

<span style="font-size:24px;">CCCallFunc *callfun = CCCallFunc::create(this, callfunc_selector(T14CCActionDemo::funcall));CCCallFuncN *callfunc = CCCallFuncN::create(this, callfuncN_selector(T14CCActionDemo::funcallN));CCCallFuncND *callfuncnd = CCCallFuncND::create(this, callfuncND_selector(T14CCActionDemo::funcallND),(void *)("90"));CCCallFuncO *callfunco = CCCallFuncO::create(this, callfuncO_selector(T14CCActionDemo::funcallO),woman);</span>
void T14CCActionDemo::funcall(){CCLog("action is ok");}void T14CCActionDemo::funcallN(CCNode* node){node->setVisible(false);}void T14CCActionDemo::funcallND(CCNode* pnode, void* pdata){CCString *str = CCString::createWithFormat("%s", pdata);pnode->setRotation(str->floatValue());}void T14CCActionDemo::funcallO(CCObject* obj){CCSprite *woman = (CCSprite *)obj;CCMoveBy *moveby = CCMoveBy::create(2, ccp(200, 0));woman->runAction(moveby);}


We can add all the false actions of some columns to CCSequence. can we determine which action has been executed through the false action? For example, there are three in a CCSequence: MoveBy, JumpBy, and CCCallFunc. When the callback of CCCallFunc is executed, does it mean that the first two actions are completed. Similarly, there are many other application scenarios,

CCCallFunc is the most basic false action. CCCallFuncN can get CCNode during callback. CCCallFuncND can get CCNode and Data during callback. Data is the Data we manually add, the above example is the "90" string. CCCallFuncO is the CCObject that we defined when it is discarded.





All the above actions are delayed, and the sample code is attached:

CCMoveTo *moveto = CCMoveTo::create(3, ccp(300, 100));CCMoveBy *moveby = CCMoveBy::create(2, ccp(200, 0));CCMoveBy *moveby2 = CCMoveBy::create(2, ccp(200, 0));CCJumpTo *jumpto = CCJumpTo::create(3, ccp(300,100), 50, 3);CCJumpBy *jumpby = CCJumpBy::create(3, ccp(200, 0), 150, 3);CCScaleTo *scaleTo = CCScaleTo::create(3, 2);CCScaleBy *scaleby = CCScaleBy::create(3, 2);CCRotateTo *rotateto = CCRotateTo::create(3, -90);CCRotateBy *rotateBy = CCRotateBy::create(3, -90);CCSpawn *spawn = CCSpawn::create(rotateto, scaleby,NULL);CCSequence *sequence = CCSequence::create(rotateto, scaleby, NULL);CCSkewTo *skewto = CCSkewTo::create(3, 222, 222);CCTintTo *tintto = CCTintTo::create(3, 255, 0, 255);CCFadeIn *fadein = CCFadeIn::create(3);CCFadeOut *fadeout = CCFadeOut::create(3);CCFadeTo *fadeto = CCFadeTo::create(3, 100);CCPointArray *pointarray = CCPointArray::create(6);pointarray->addControlPoint(ccp(100, 160));pointarray->addControlPoint(ccp(200, 160));pointarray->addControlPoint(ccp(200, 250));pointarray->addControlPoint(ccp(300, 250));pointarray->addControlPoint(ccp(300, 160));pointarray->addControlPoint(ccp(450, 160));CCCardinalSplineTo *cardinal = CCCardinalSplineTo::create(10, pointarray, 1);CCBlink *blink = CCBlink::create(3, 5);CCEaseExponentialIn *exponentin = CCEaseExponentialIn::create(moveby);CCEaseBackIn *bakcin = CCEaseBackIn::create(moveby);

There are a lot of methods. For details, you can refer to the api. If you really don't understand it, you can refer to the api Based on the instance above. For some buffering, You can do experiments by yourself, in this case, I will not talk about your own practice.


Finally, CCSpeed and CCFollow are available. CCSpeed mainly focuses on variable speed:

CCSpeed * speed = CCSpeed: create (moveby, 5); // increase the speed by 5 times

CCFollow: I am not talking about CCFollow. I just did my own experiment. Let's get it here today.



All right, I want to go to bed early. I have to go to bed before. Good night ~




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.