微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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


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;
}

原文地址:https://www.jb51.cc/cocos2dx/341643.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐