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: