Here is Evankaka 's blog, Welcome to discuss and communicate with you before ~~~~~~
Reprint Please specify the source http://blog.csdn.net/evankaka/article/details/42740575
one of the features that will be implemented here is that when a monster's injury is reduced, a number of the amount of blood that is deducted from the monster will float to the top of the head and disappear. Then there are two ways, one is to buckle the same number each time, one is a certain range of numbers at random, the article on the blogger's article http://blog.csdn.net/evankaka/article/details/42689689.
Cocos2d-x version: 2.2.5
Engineering Environment: WINDOWS7+VS2010
Open by: Put the project under the project folder in the Cocos2d-x installation directory with VS Open
Effect:
Directory
One, self-fixed buckle blood floating word effect class Flyword
Ii. Methods of Use
Iii. Summary of Ideas
One, self-fixed buckle blood floating word effect class Flyword
Actually here is a Cclabelttf type to perform the animation Ccmoveby a process
Here's a look at my own definition, header file FlyWord.h
#ifndef __flyword_h__#define __flyword_h__#include "cocos2d.h" #include "cocos-ext.h" USING_NS_CC; Using_ns_cc_ext; Class Flyword:public ccnode{public://creates a text flare, create and Init are linked together, calling create will inevitably call Initstatic flyword* Create (const char *word,const int fontsize,ccpoint begin); The//init method accepts 3 parameters, namely the floating string, the font size, where it starts to float, The Init method is primarily initialized with the Floatword built-in Labelbool init (const char *word,const int fontsize,ccpoint begin);//text from bottom to top fluttering void Flying () ;//text fluttering after deleting all objects void Flyend ();p rivate:int _fontsize;//font size ccpoint _begin;//The center point of the monster to add cclabelttf* m_plabel;//font type};# endif//__flyword_h__
Then the implementation class FlyWord.cpp
#include "FlyWord.h" flyword* flyword::create (const char *word,const int fontsize,ccpoint begin) {flyword* ret = new Flywor D ();//It is safer to write some if (ret && ret->init (word,fontsize,begin)) {ret->autorelease (); return ret;} Cc_safe_delete (ret);//Safely remove return nullptr;} BOOL Flyword::init (const char *word,const int fontsize,ccpoint begin) {if (! Ccnode::init ()) {return false;} Initialize _begin = Begin;m_plabel = Cclabelttf::create (Word, "Marker Felt", fontSize);//Set color cccolor3b RGB; rgb.r=255; rgb.g=0; Rgb.b=0;m_plabel->setcolor (RGB); This->addchild (M_plabel); This->setposition (CCP (BEGIN.X,BEGIN.Y));// After the initialization is complete, the word flying () is started, and return is true; The text is floated from bottom to top void flyword::flying () {ccmoveby* moveact=ccmoveby::create (0.5f,ccpointmake (0,70));//0.5 seconds Move up 70//create callback action , cccallfunc* callfunc=cccallfunc::create (This,callfunc_selector (flyword::flyend)) after the text has been streamed out;// Create a continuous action ccactioninterval* act=ccsequence::create (Moveact,callfunc,null);//setvisible (true); This->runaction (act );} void Flyword::flyend () {//To remove the object from memory after completion this->removealLchildrenwithcleanup (True); This->removefromparentandcleanup (true);}
There's a lot of detail in the code, and I'm not going to explain it anymore.
Ii. Methods of Use
Add header file # include "FlyWord.h" in Monster.h or Monster.cpp
The following is a randomly generated 10-30 of the amount of blood to reduce, which is more common in the game, the monster each time the amount of injury may be different.
Injured animation end void Monster::hurtend () {ishurt=false;//produces 10-30 of a random amount of blood srand (UINT) getcurrenttime ()); int x = rand ()%30+10;/ /turn character char szname[100] = {0}; sprintf (SzName, "-%d", x);//Monster Drop Blood monster_xue->setcurrentprogress (Monster_xue->getcurrentprogress ()-X);// Flyword *wen_zi=flyword::create (Szname,30,ccpointmake (0,0));//placed in the current monster's (0,0) position, here (0,0) is its center, specifically can see the anchor point this- >addchild (wen_zi,2); if (monster_xue->getcurrentprogress () ==0) {//play Monster Death animation deadanimation ("Monster_dead", 2, Monsterdirecton);}}
If you want to make a monster every time the amount of injury is the same, very simple, code for
Injured animation end void Monster::hurtend () {ishurt=false;////produces 10-30 of a random amount of blood//srand (UINT) getcurrenttime ());//int x = rand ()% 30+10;//character char szname[100] = {0}; sprintf (SzName, "-%d", 10);//Monster Drop Blood monster_xue->setcurrentprogress (Monster_xue->getcurrentprogress ()-10);// Flyword *wen_zi=flyword::create (Szname,30,ccpointmake (0,0));//placed in the current monster's (0,0) position, here (0,0) is its center, specifically can see the anchor point this- >addchild (wen_zi,2); if (monster_xue->getcurrentprogress () ==0) {//play Monster Death animation deadanimation ("Monster_dead", 2, Monsterdirecton);}}
1.10-30 randomly dropped blood. Text from bottom to top
2. Fix the Blood,text from bottom to top
Iii. Summary of Ideas
The main is the design of this text class, here my train of thought get the position of hero, then cclabelttf to like to move up from the middle position of the hero, perform the animation Ccmoveby a process After the move is written, it releases itself (Removeallchildrenwithcleanup (True) and Removefromparentandcleanup (true);). Used to throw away once, and then wait for the monster to drop the blood, and then use, and then throw, more convenient ~ Game development process Sometimes the idea is really important ah!
Cocos2d-x buckle Blood drift word effect run out you will disappear-the game development "Zhao Yun to Fight" (8)