cocos2dx源码:popup实现
来源:互联网 发布:axure软件下载 编辑:程序博客网 时间:2024/05/18 00:41
头文件Popup.h
#ifndef _POPUP_H_#define _POPUP_H_#include "cocos2d.h"#include "GmbsCocos.h"#include "ui/CocosGUI.h"USING_NS_CC;class Popup : public LayerColor{ //typedef std::function<void(void)> showEnd_t;public: Popup(); ~Popup(); bool create(Size &size, const char* bgFileName, bool autorelease = true); virtual bool init(); void show(float seconds, bool removedWhenShowEnd = true, std::function<void(void)> showEndCallback = nullptr); void show01(float seconds, bool removedWhenShowEnd = true, std::function<void(void)> showEndCallback = nullptr); void showEnd(); void showWithAction(ActionInterval* action, bool removedWhenShowEnd, std::function<void(void)> showEndCallback); void setVisible(bool visible); void setHideCallback(std::function<void(void)> showEndCallback) { m_showEndCallback = showEndCallback; } void setHideWhenTouch(bool hideWhenTouch) { m_hideWhenTouch = hideWhenTouch; }protected: virtual bool onTouchBegan(Touch *pTouch, Event *pEvent); EventListenerTouchOneByOne* m_touchListener; ui::Scale9Sprite* m_background; std::function<void(void)> m_showEndCallback; bool m_removedWhenShowEnd; bool m_hideWhenTouch;};#endif
源文件Popup.cpp
#include "Popup.h"Popup::Popup(){ m_touchListener = nullptr; m_showEndCallback = nullptr; m_hideWhenTouch = false; m_removedWhenShowEnd = false;}Popup::~Popup(){}bool Popup::create(Size &size, const char* bgFileName, bool autorelease){ if (!this->initWithColor(Color4B(0, 0, 0, 0))) return false; if (autorelease) this->autorelease(); this->setContentSize(size); m_background = nullptr; if (bgFileName != nullptr) { GmbsPoint pt; m_background = ui::Scale9Sprite::create(bgFileName); this->addChild(m_background); m_background->setAnchorPoint(Vec2(0.5, 0.5)); m_background->setContentSize(size); m_background->setColor(Color3B(255, 133, 52)); m_background->setOpacity(220); pt.reset(m_background); pt.xMiddleAlign(this).yMiddleAlign(this); m_background->setPosition(pt); Size frameSize(size.width + 4, size.height + 4); ui::Scale9Sprite* frame = ui::Scale9Sprite::create(bgFileName); this->addChild(frame, -1); frame->setAnchorPoint(Vec2(0.5, 0.5)); frame->setContentSize(frameSize); frame->setColor(Color3B(255, 255, 255)); pt.reset(frame); pt.xMiddleAlign(m_background).yMiddleAlign(m_background); frame->setPosition(pt); } setVisible(true); return this->init();}bool Popup::init(){ return true;}void Popup::setVisible(bool visible){ if (visible && !m_touchListener) { m_touchListener = EventListenerTouchOneByOne::create(); m_touchListener->onTouchBegan = CC_CALLBACK_2(Popup::onTouchBegan, this);; m_touchListener->setSwallowTouches(true); _eventDispatcher->addEventListenerWithSceneGraphPriority(m_touchListener, this); } else if (!visible && m_touchListener) { _eventDispatcher->removeEventListener(m_touchListener); m_touchListener = nullptr; } LayerColor::setVisible(visible);}bool Popup::onTouchBegan(Touch *pTouch, Event *pEvent){ if (m_hideWhenTouch) { Size size = getContentSize(); Rect boundingRect(0, 0, size.width, size.height); Point touchPoint = convertTouchToNodeSpace(pTouch); if (!boundingRect.containsPoint(touchPoint)) { showEnd(); } } return true;}void Popup::show(float seconds, bool removedWhenShowEnd, std::function<void(void)> showEndCallback){ auto action = Sequence::create( DelayTime::create(seconds), CallFunc::create(CC_CALLBACK_0(Popup::showEnd, this)), nullptr); this->showWithAction(action, removedWhenShowEnd, showEndCallback);}void Popup::show01(float seconds, bool removedWhenShowEnd, std::function<void(void)> showEndCallback){ setScale(0); auto action = Sequence::create( ScaleTo::create(0.8f, 1.25f), DelayTime::create(seconds), CallFunc::create(CC_CALLBACK_0(Popup::showEnd, this)), nullptr); this->showWithAction(action, removedWhenShowEnd, showEndCallback);}void Popup::showWithAction(ActionInterval* action, bool removedWhenShowEnd, std::function<void(void)> showEndCallback){ this->stopActionByTag(1); action->setTag(1); this->runAction(action); setVisible(true); m_removedWhenShowEnd = removedWhenShowEnd; m_showEndCallback = showEndCallback;}void Popup::showEnd(){ setVisible(false); if (m_showEndCallback) m_showEndCallback(); if (m_removedWhenShowEnd) this->removeFromParent();}
0 0
- cocos2dx源码:popup实现
- 怎样实现POPUp
- div+javascript实现popup
- div+javascript实现popup
- openlayers的popup实现
- css实现tip popup
- WPF Popup实现拖动
- Cocos2dx源码分析之JumpBy的实现
- 不用屏幕实现ALV POPUP
- 实现半透明的popup window
- POPUP
- Popup
- popup
- popup
- popup
- popup
- popup
- popup
- Xcode 生成Appium可自动化的包
- 宿主主机与VMware中虚拟机网络通信设置
- Nginx日志导入到Hive0.13.1,同步Hbase0.96.2,设置RowKey为autoincrement(ID自增长)
- 解决jQuery $.getJSON() 传递参数中文乱码问题
- 基于社交网络的用户与基于物品的协同过滤推荐算法-java
- cocos2dx源码:popup实现
- Android全屏,隐藏底部虚拟键
- JSP传递值给servlet的方式
- Golang、Php、Python、Java基于Thrift0.9.1实现跨语言调用
- 获取通讯录联系人,选择后返回
- 安装cdh 版的impala
- 架构:Android的MVVM
- SeekBar的基本使用
- CKEditor的安装与基本使用(JSP)