设为首页 加入收藏

TOP

仿《雷霆战机》飞行射击手游开发--新手引导(四)
2017-10-13 10:14:57 】 浏览:3251
Tags:《雷霆战机》 飞行 射击 开发 新手 引导
m_prompt; bool m_touchEnable; };

这个类中,最重要的就是doInit函数,其功能包括了:把目标按钮从原来的父节点上摘下来,挂到半透明层上。

		m_targetPos = m_pTarget->getPosition();
		m_targetParent = m_pTarget->getParent();
		m_targetLocalZOrder = m_pTarget->getLocalZOrder();

		//Vec2 pos = m_pRoot->convertToWorldSpace(m_pTarget->getPosition());
		Vec2 pos = m_pTarget->convertToWorldSpace(Vec2::ZERO);
		pos += m_pTarget->getAnchorPointInPoints();

		//将target移到本layer上
		m_pRoot->addChild(this);
		m_pTarget->retain();
		this->addChild(m_pTarget);
		m_pTarget->release();
		m_pTarget->setPosition(pos);

添加指示箭头动画

		//m_pTarget的中心位置(根据锚点进行转换)
		float deltaX = (0.5 - m_pTarget->getAnchorPoint().x) * m_pTarget->getAnchorPointInPoints().x / m_pTarget->getAnchorPoint().x;
		float deltaY = (0.5 - m_pTarget->getAnchorPoint().y) * m_pTarget->getAnchorPointInPoints().y / m_pTarget->getAnchorPoint().y;

		//添加指示箭头
		Sprite* pArrow = Sprite::createWithSpriteFrameName("Guide_Arrow.png");
		const Size& targetSize = m_pTarget->getContentSize();
		const Size& arrowSize = pArrow->getContentSize();
		bool bArrowTop = true;

		Node* pDialogBox = nullptr;
		Sprite* pDialogBoxBg = nullptr;
		ui::Text* m_pTextPrompt = nullptr;
		if (m_prompt.length() > 0)
		{
			pDialogBox = Preload::getInstance()->getUI("GameUI_Dialogbox.csb");
			FIND_UI_CONTROL_RE(ui::Text*, "Text_Content", m_pTextPrompt, pDialogBox);
			FIND_UI_CONTROL_RE(Sprite*, "GameUI_Dialogbox_Bg", pDialogBoxBg, pDialogBox);
			m_pTextPrompt->setTextAreaSize(Size(360, 110));
			m_pTextPrompt->ignoreContentAdaptWithSize(false);
		}
		if (m_pTarget->getPositionY() < CONSTANT::DESIGN_RES_HEIGHT / 2 + 100)
		{
			//箭头在控件的上方
			bArrowTop = true;
			pArrow->setPosition(m_pTarget->getPosition().x + deltaX,
				m_pTarget->getPosition().y + targetSize.height / 2 + arrowSize.height / 2 + 20 + deltaY);
		
			if (pDialogBox)
			{
				pDialogBox->setPosition(CONSTANT::DESIGN_RES_WIDTH / 2, CONSTANT::DESIGN_RES_HEIGHT - pDialogBoxBg->getContentSize().height / 2);
				m_pTextPrompt->setString(m_prompt);
				this->addChild(pDialogBox);
			}
		}
		else
		{
			//箭头在控件的下方
			bArrowTop = false;
			pArrow->setFlippedY(true);
			pArrow->setPosition(m_pTarget->getPosition().x + deltaX,
				m_pTarget->getPosition().y - targetSize.height / 2 - arrowSize.height / 2 - 20 + deltaY);
			
			if (pDialogBox)
			{
				pDialogBox->setPosition(CONSTANT::DESIGN_RES_WIDTH / 2, pDialogBoxBg->getContentSize().height / 2);
				m_pTextPrompt->setString(m_prompt);
				this->addChild(pDialogBox);
			}
		}
		this->addChild(pArrow);

		//箭头动画
		DelayTime* pDelay = DelayTime::create(0.4f);
		MoveBy* pMove1 = MoveBy::create(0.15f, Vec2(0, -10.0f));
		MoveBy* pMove2 = MoveBy::create(0.15f, Vec2(0, 10.0f));
		Sequence* pSeq = nullptr;
		if (bArrowTop)
		{
			pSeq = Sequence::create(pDelay, pMove1, pMove2, nullptr);
		}
		else
		{
			pSeq = Sequence::create(pDelay, pMove2, pMove1, nullptr);
		}
		RepeatForever* pRepeat = RepeatForever::create(pSeq);
		pArrow->runAction(pRepeat);
首页 上一页 1 2 3 4 5 下一页 尾页 4/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇13:图像模糊处理 下一篇ReplaceChar

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目