加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

【cocos2d-x 3.7 飞机大战】 决战南海I (九) 飘字特效

发布时间:2020-12-14 16:27:31 所属栏目:百科 来源:网络整理
导读:之前在一个闯关游戏中第一次接触飘字效果,因为那个游戏没有发教程,所以在这里介绍下飘字效果 class FlowWord :public Node{public:FlowWord();~FlowWord();//创建和初始化 飘字static FlowWord* create();bool init();//显示飘字void showFlowWord(const c

之前在一个闯关游戏中第一次接触飘字效果,因为那个游戏没有发教程,所以在这里介绍下飘字效果


class FlowWord :public Node
{
public:
	FlowWord();
	~FlowWord();

	//创建和初始化 飘字
	static FlowWord* create();
	bool init();

	//显示飘字
	void showFlowWord(const char* text,Point pos,ActionInterval* flowWord);

	//显示飘字结束
	void showEnd();

//	ActionInterval* beginFlowWord();

//	ActionInterval* propFlowWord();

	ActionInterval* otherFlowWord();
protected:
private:

	Label* m_textLabel;
};


在这个类中,内置了几种常见的飘字动作和一个飘字函数(需要传入 飘字内容、位置、动作)


其实现如下

bool FlowWord::init()
{
	m_textLabel = Label::createWithTTF("","fonts/DFPShaoNvW5-GB.ttf",25);
	m_textLabel->setColor(ccc3(CCRANDOM_0_1() * 255,CCRANDOM_0_1() * 255,CCRANDOM_0_1() * 255));
	m_textLabel->setAnchorPoint(ccp(1,0));
	m_textLabel->setVisible(false);

	this->addChild(m_textLabel);

	return true;
}

//显示飘字
void FlowWord::showFlowWord(const char* text,ActionInterval* flowWord)
{

	m_textLabel->setPosition(pos);
	m_textLabel->setString(text);
	m_textLabel->setVisible(true);

	m_textLabel->runAction(flowWord);
}

//显示飘字结束
void FlowWord::showEnd()
{
	CCLOG("showWord End!");
	m_textLabel->setVisible(false);
	m_textLabel->removeFromParentAndCleanup(true);
}



#if 0
//游戏开始飘字
ActionInterval* FlowWord::beginFlowWord()
{
	//放大缩小
	ActionInterval* m_scaleLarge = ScaleTo::create(2.0f,2.5,2.5);
	ActionInterval* m_scaleSmall = ScaleTo::create(2.0f,0.5,0.5);

	//倾斜
	ActionInterval* m_skew = SkewTo::create(2.0f,180,0);
	ActionInterval* m_skewBack = SkewTo::create(2.0f,0);

	//组合动作
	ActionInterval* m_action = Spawn::create(m_scaleLarge,m_skew,NULL);
	ActionInterval* m_actionBack = Spawn::create(m_scaleSmall,m_skewBack,NULL);

	CallFunc* callFunc = CallFunc::create(this,callfunc_selector(FlowWord::showEnd));

	ActionInterval* flow = Sequence::create(m_action,m_actionBack,callFunc,NULL);

	return flow;
}

//获得道具飘字
ActionInterval* FlowWord::propFlowWord()
{
	//放大缩小
	ActionInterval* m_scaleLarge = ScaleTo::create(2.0f,0.5);

	CallFunc* callFunc = CallFunc::create(this,callfunc_selector(FlowWord::showEnd));

	ActionInterval* flow = Sequence::create(m_scaleLarge,m_scaleSmall,NULL);

	return flow;
}

#endif

//其它飘字
ActionInterval* FlowWord::otherFlowWord()
{
	//移位
	ActionInterval* m_move1 = MoveBy::create(2.0f,ccp(30,30));
	ActionInterval* m_move2 = MoveBy::create(2.0f,ccp(-30,-30));
	ActionInterval* m_move3 = MoveBy::create(2.0f,-30));
	ActionInterval* m_move4 = MoveBy::create(2.0f,30));

	//放大缩小
	ActionInterval* m_scale1 = ScaleTo::create(2.0f,CCRANDOM_0_1() * 4,CCRANDOM_0_1() * 4);
	ActionInterval* m_scale2 = ScaleTo::create(2.0f,CCRANDOM_0_1() * 4);
	ActionInterval* m_scale3 = ScaleTo::create(2.0f,CCRANDOM_0_1() * 4);
	ActionInterval* m_scale4 = ScaleTo::create(2.0f,CCRANDOM_0_1() * 4);

	ActionInterval* m_action1 = Spawn::create(m_move1,m_scale1,NULL);
	ActionInterval* m_action2 = Spawn::create(m_move2,m_scale2,NULL);
	ActionInterval* m_action3 = Spawn::create(m_move3,m_scale3,NULL);
	ActionInterval* m_action4 = Spawn::create(m_move4,m_scale4,NULL);


	CallFunc* callFunc = CallFunc::create(this,callfunc_selector(FlowWord::showEnd));

	ActionInterval* flow = Sequence::create(m_action1,m_action2,m_action3,m_action4,NULL);

	return flow;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读