Cocos2d-x 3.4 Action Management (ActionManager) Summary

Source: Internet
Author: User


cocos2d-x Action Management

The Action management class Ccactionmanager is a single instance that manages actions, and works by ccnode the action to pass the object to Ccactionmanager's singleton through the Addaction function of the action management class when the runaction is executed. The instance then adds this action to its own sequence of actions.

The action Management Singleton refreshes its own Update method by timing, and in this method calls the step of each action in the behavior sequence (the paused behavior is not updated), and the step method then updates or ends the behavior according to its completion progress.

In fact, each action driven by the action management Singleton is updated with its own logic, and the Runaction method simply adds the behavior object to the Ccactionmanager's pending queue. When a node is purged or the behavior ends, the action management class automatically removes the action from the queue without the programmer's management.

In general, you do not need to use this singleton to manage actions, you can use functions such as stopaction, Stopactionbytag, and stopactions of the Ccnode class to manage, but there are two cases where you need to use a Ccactionmanager class singleton:

The performer of the <1> action is not the same node. <2> when the activity needs to be paused/restarted.


first, cc_callback_0 without parameters

Auto Child = Sprite::create ("Images/grossini.png");

Rect r = director::getinstance ()->getopenglview ()->getvisiblerect ();

VEC2 v2 = Vec2 (r.origin.x+300,r.origin.y/2+r.size.height-300);

Child->setposition (v2);

AddChild (child,1);

Child->runaction (Rotateby::create (1.5f,90));//rotation 90 degrees clockwise

Child->runaction (Sequence::create (Delaytime::create (1.4f), Fadeout::create (1.1f), nullptr));//1.4 seconds later, disappears

Child->runaction (Sequence::create (Delaytime::create (1.4f), Callfunc::create (cc_callback_0:: Remove, this)) (nullptr));//After 1.4 seconds, execute the Remove method


void HelloWorld::Remove() {

Cclog ("bbbbbbbbbb");

}


two, cc_callback_1 with a parameter

Auto Child1 = sprite::create ("Images/grossini.png");

AddChild (child1,0,2);

Rect r1 = director::getinstance ()->getopenglview ()->getvisiblerect ();

VEC2 v2 = Vec2 (r1.origin.x+300,r1.origin.y/2+r1.size.height-300);

Child1->setposition (v2);

Child1->runaction (Sequence::create (Moveby::create (1,VEC2 (150,0)), Callfuncn::create (CC_CALLBACK_1 (HelloWorld :: Update1,this)), nullptr);

void Helloworld::update1 (node* Node) {

Node->stopallactions ();

Node->runaction (Scaleto::create (2,2));

RemoveChild (node);

}


Three, Cc_schedule_selector first perform an action and then perform an action on a regular basis

Auto Child2 = sprite::create ("Images/grossini.png");

AddChild (child2,0,121);

Rect r1 = director::getinstance ()->getopenglview ()->getvisiblerect ();

VEC2 v2 = Vec2 (r1.origin.x + 300,R1.ORIGIN.Y/2 + r1.size.height-300);

Child2->setposition (v2);

Auto action = moveby::create (1,VEC2 (150,0));

Auto director = Director::getinstance ();

Director->getactionmanager ()->addaction (action,child2,true);

Schedule (Cc_schedule_selector (Helloworld::unpause), 3);//3 seconds after the Unpause method is executed


void Helloworld::unpause (float dt) {

Unschedule (Cc_schedule_selector (helloworld::unpause));

Auto node =getchildbytag (121);

Auto director = Director::getinstance ();

ccaction* action1 = ccrotateby::create (1, 360);

Director->getactionmanager ()->resumetarget (node);

Node->runaction (Action1);

}


Iv. Stop action after performing an action

Auto Child2 = sprite::create ("Images/grossini.png");

Rect r1 = director::getinstance ()->getopenglview ()->getvisiblerect ();

VEC2 v2 = Vec2 (r1.origin.x +300,r1.origin.y/2 +r1.size.height-300);

Child2->setposition (v2);

AddChild (child2,0,111);

    Auto Pmove = moveby::create (2,

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.