Cocos2dx3.2 compile common UI components (3) Collector effect Collector

Source: Internet
Author: User

Cocos2dx3.2 compile common UI components (3) Collector effect Collector

Preface:

In the game, we often see that after scores are obtained, the scores are automatically raised to the corresponding score bar. Today we will achieve this effect.

Body:

This effect is actually very simple. You only need to add an action to the generated score (usually a Sprite or Node) so that it can be moved to the target position and then disappear. Here I provide a Collector class for you to use. Convenient operations.

Collector usage instructions: ① use the Collector: create () function to create a Collector object

② First, set the Collector location.

③ If you need to set the callback function after the element reaches the Collector, use Collector: setCallback (std: function ) Function

④ For the created Node, you only need to use Collector: addSource (node * Node) to add it to the collector object. Then the newly created node will automatically flow to the collector location.

⑤ Use the Collector: setTime function to set the floating time

Example:

 

c = Collector::create();c->setPosition(240,160);this->addChild(c);
void HelloWorld::menuCloseCallback(Ref* pSender){Sprite* sp = Sprite::create(CloseNormal.png);sp->setPosition(100,100);this->addChild(sp);c->addSource(sp);}

The effect is as follows:

 

 

Collector class is very simple. Let's look at the most important addSoruce function.

 

void Collector::addSource(Node* node){MoveTo* moveTo = MoveTo::create(m_time,this->getPosition());EaseBackInOut* easeMove = EaseBackInOut::create(moveTo);ScaleTo* scaleBig = ScaleTo::create(0.3*m_time,1.5f);ScaleTo* scaleSmall = ScaleTo::create(0.7*m_time,0.5f);Sequence* scale = Sequence::create(scaleBig,scaleSmall,NULL);Spawn* move = Spawn::create(easeMove,scale,NULL);CallFunc* callFunc = CallFunc::create([=](){node->removeFromParentAndCleanup(true);m_callback();});Sequence* action = Sequence::create(move,callFunc,NULL);node->runAction(action);}
The addSource function encapsulates a series of actions and then allows Node to execute them.

 

 

 

Related Article

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.