cocos2dx-3.0 : EventListener
2013-11-22 12:58
113 查看
#ifndef cocos2d_libs_EventListener_h #define cocos2d_libs_EventListener_h #include "CCPlatformMacros.h" #include "CCObject.h" #include <functional> #include <string> #include <memory> #include <set> NS_CC_BEGIN class Event; class Node; /** * The base class of event listener. * If you need custom listener which with different callback, you need to inherit this class. * For instance, you could refer to EventListenerAcceleration, EventListenerKeyboard, EventListenerTouchOneByOne, EventListenerCustom. */ class EventListener : public Object { public: enum class Type { UNKNOWN, TOUCH_ONE_BY_ONE, TOUCH_ALL_AT_ONCE, KEYBOARD, MOUSE, ACCELERATION, CUSTOM }; typedef std::size_t ListenerID; protected: /** Constructor */ EventListener(); /** Initializes event with type and callback function */ bool init(Type t, ListenerID listenerID, std::function<void(Event*)>callback); public: /** Destructor */ virtual ~EventListener(); /** 检查该监听是否有效 */ virtual bool checkAvailable() = 0; /** Clones the listener, its subclasses have to override this method. */ virtual EventListener* clone() = 0; protected: inline void setPaused(bool paused) { _paused = paused; }; inline bool isPaused() const { return _paused; }; inline void setRegistered(bool registered) { _isRegistered = registered; }; inline bool isRegistered() const { return _isRegistered; }; inline Type getType() const { return _type; }; inline ListenerID getListenerID() const { return _listenerID; }; inline void setFixedPriority(int fixedPriority) { _fixedPriority = fixedPriority; }; inline int getFixedPriority() const { return _fixedPriority; }; inline void setSceneGraphPriority(Node* node) { _node = node; }; inline Node* getSceneGraphPriority() const { return _node; }; std::function<void(Event*)> _onEvent; /// 事件响应函数; c++11 Type _type; /// 事件类型,区分重力事件,键盘事件,touch 事件等 ListenerID _listenerID; /// Event listener ID bool _isRegistered; /// 该监听是否被注册到dispather中 // The priority of event listener int _fixedPriority; // 数值越大,优先级越高。0则表示基于场景图优先级 Node* _node; // 场景图优先级 bool _paused; // 该监听是否暂停 friend class EventDispatcher; }; NS_CC_END #endif
相关文章推荐
- cocos2dx 3.0 无法解析的外部符号 __imp__curl_easy_setopt,
- vs引入新lib-----附cocos2dx3.0 http通信lib库添加
- 24、Cocos2dx 3.0游戏开发找小三之网格动作:高炫酷的3D动作
- cocos2dx 3.0以上创建项目步骤及生成apk
- cocos2dx3.0游戏编程3-动作游戏之类对象交互
- cocos2dx3.0 + eclipse + android + lua环境配置
- 对于cocos2dx,3.0的android编译问题
- Cocos2dx3.0初认识
- Cocos2dx 3.0 过渡篇(三十一)ValueVector和Vector不得不说的故事
- cocos2dx 3.0 环境搭建
- cocos2dx3.0 DrawNode的使用
- cocos2dx 3.0 alpha1 + cocostudio UI Editor编辑器
- Cocos2dx 3.0 过渡篇(二十六)C++11多线程std::thread的简单使用
- Cocos2dx 3.0 过渡篇(三) 触摸机制
- COCOS2DX3.0的3种触摸响应机制
- Cocos2dx 3.0游戏开发找小三之Cocos2d-x的动作机制:嘻,善哉!技盖至此乎?
- win平台下搭建cocos2dx 3.0+ lua开发环境 VS2012+sublime text+lua 5.2.3
- 一步一步了解Cocos2dx 3.0 正式版本开发环境搭建(Win32/Android)
- cocos2dx 3.0 自学 No.1 override
- cocos2dx3.0 C++开发 零基础入门笔记