游戏中经常需要用到一串字体从右到左的飘入,用于显示关卡等信息。在这里我创建了一个继承Node的一个类:FloatWord,大家也可以自己建一个自己觉得好用的飘字效果类。
头文件FloatWord.h
class FloatWord : public Node{
public:
static FloatWord* create(const std::string& word,const int fontSize,Point begin);
bool init(const std::string& word,const int fontSize,Point begin);
void floatIn(const float delay,std::function<void()> callback);
void floatOut(const float delay,std::function<void()> callback);
void floatInOut(const float speed,const float delay,std::function<void()> callback);
private:
int _fontSize;
Point _begin;
Label* _label;
};
1)create 和 init 是连在一起的,调用create的时候必然会调用init
FloatWord* FloatWord::create(const std::string& word,const int fontSize,Point begin){
FloatWord* ret = new FloatWord();
if(ret && ret->init(word,fontSize,begin)){
ret->autorelease();
return ret;
}
CC_SAFE_DELETE