cocos2d-x节点(CCEventListener.h)API

来源:互联网 发布:美工外包 编辑:程序博客网 时间:2024/05/18 01:24

本文来自http://blog.csdn.net/runaying ,引用必须注明出处!

cocos2d-x节点(CCEventListener.h)API

温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记

监听器的基类

///cocos2d/cocos2d-x-3.0alpha0/cocos2dx/event_dispatcher//监听器的基类#ifndef cocos2d_libs_EventListener_h#define cocos2d_libs_EventListener_h#include "platform/CCPlatformMacros.h"#include "cocoa/CCObject.h"#include <functional>#include <string>#include <memory>NS_CC_BEGINclass Event;/** *  事件侦听器的基类. * 如果你需要使用不同的回调自定义监听时,你需要继承这个类 *  例如你可以参考 AccelerationEventListener, KeyboardEventListener or TouchEventListener, CustomEventListener. */class EventListener : public Object{    protected:    /** 构造函数 */    EventListener();        /** 使用 事件类型和回调函数 初始化事件 */    bool init(const std::string& t, std::function<void(Event*)>callback);public:    /** 析构函数 */    virtual ~EventListener();        /** 检查侦听器是否可用. */    virtual bool checkAvaiable() = 0;        /** 克隆监听器,它的子类必须重写此方法. */    virtual EventListener* clone() = 0;protected:    std::function<void(Event*)> _onEvent;   /// Event 回调函数    std::string _type;                      /// Event 类型    bool _isRegistered;                    ///侦听器是否已被添加到调度器        friend class EventDispatcher;    friend class Node;};NS_CC_END#endif


原创粉丝点击