Cocos2D-x game development 13th: custom game flashing tips

Source: Internet
Author: User

Now we use the knowledge we have learned to implement a class to complete the flickering prompt information when the protagonist or obstacle in the game is under attack.

There is nothing new, so cainiao can understand it. In addition, I also want to emphasize that in small aspects, the game needs innovation and the effects of game development need innovation, innovation is not so difficult. Using simple knowledge, we can innovate just like ours.

Let's talk a lot about the Code:

Class FlowWord: public CCNode {public: static FlowWord * create (); bool init (); public: void showWord (const char * text, CCPoint pos); private: CCLabelTTF * m_textLab; void flowEnd () ;}; FlowWord * FlowWord: create () {FlowWord * flowWord = new FlowWord (); if (flowWord & flowWord-> init ()) {flowWord-> autorelease ();} else {CC_SAFE_DELETE (flowWord);} return flowWord;} bool FlowWord: init () {m_textLab = CCLabelTTF: create ("", "Arial", 35); m_textLab-> setColor (ccc3 (255, 0, 0); m_textLab-> setAnchorPoint (ccp (1, 0 )); m_textLab-> setVisible (false); this-> addChild (m_textLab); return true;} void FlowWord: showWord (const char * text, CCPoint pos) {m_textLab-> setString (text); m_textLab-> setPosition (pos); m_textLab-> setVisible (true);/* combines two actions, zoom in and zoom out */CCActionInterval * scaleLarge = CCScaleTo: create (0.3f, 2.5f, 2.5f); CCActionInterval * scaleSmall = CCScaleTo: create (0.5f, 0.5f, 0.5f ); CCCallFunc * callFunc = CCCallFunc: create (this, callfunc_selector (FlowWord: flowEnd); CCActionInterval * actions = CCSequence: create (scaleLarge, scaleSmall, callFunc, NULL ); m_textLab-> runAction (actions);} void FlowWord: flowEnd () {/* Action ended, deleting itself from the parent node */m_textLab-> setVisible (false ); m_textLab-> removeFromParentAndCleanup (true );}


 

Now we can use it to achieve our results. Add the following code as needed:

FlowWord *flowword = FlowWord::create();this->addChild(flowword);flowword->showWord("-15",GetSprite()->getPosition());


The effect is as follows:



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.