首页 > 其他 > 详细

cocos2dx自定义事件类封装

时间:2015-03-10 10:06:13      阅读:1297      评论:0      收藏:0      [点我收藏+]

GameEvent.h:

 1 #pragma once
 2 #include "cocos2d.h"
 3 USING_NS_CC;
 4 
 5 class GameEvent {
 6 public:
 7     //封装派发数据
 8     static void dispatchSet(std::string eventName, void *optionalUserData = nullptr);
 9     static void dispatch(std::string eventName, void *optionalUserData = nullptr);
10     static void addEventListener(std::string eventName, const std::function<void(EventCustom*)>& callback);
11     static void removeEventListener(std::string eventName);
12 };

GameEvent.cpp:

 1 #include "GameEvent.h"
 2 
 3 
 4 
 5 void GameEvent::dispatch(std::string eventName, void *optionalUserData) {
 6     Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(eventName, optionalUserData);
 7 }
 8 
 9 void GameEvent::addEventListener(std::string eventName, const std::function<void(EventCustom*)>& callback) {
10     Director::getInstance()->getEventDispatcher()->addCustomEventListener(eventName, callback);
11 }
12 
13 void GameEvent::removeEventListener(std::string eventName) {
14     Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(eventName);
15 }

 

cocos2dx自定义事件类封装

原文:http://www.cnblogs.com/xyida/p/4325067.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!