码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2dx自定义事件类封装

时间:2015-03-10 10:08:41      阅读:1102      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!