GameEvent.h:

 #pragma once
#include "cocos2d.h"
USING_NS_CC; class GameEvent {
public:
//封装派发数据
static void dispatchSet(std::string eventName, void *optionalUserData = nullptr);
static void dispatch(std::string eventName, void *optionalUserData = nullptr);
static void addEventListener(std::string eventName, const std::function<void(EventCustom*)>& callback);
static void removeEventListener(std::string eventName);
};

GameEvent.cpp:

 #include "GameEvent.h"

 void GameEvent::dispatch(std::string eventName, void *optionalUserData) {
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(eventName, optionalUserData);
} void GameEvent::addEventListener(std::string eventName, const std::function<void(EventCustom*)>& callback) {
Director::getInstance()->getEventDispatcher()->addCustomEventListener(eventName, callback);
} void GameEvent::removeEventListener(std::string eventName) {
Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(eventName);
}

cocos2dx自定义事件类封装的更多相关文章

  1. 自定义事件类EventManager (TS中...args的使用例子)

    一个自定义事件类 初衷是使用Egret的事件有两点比较麻烦 1   在事件处理函数时,需要从e中获取data hander(e:egret.Event){ let data = e.data; } 2 ...

  2. 编写一个自定义事件类,包含on/off/emit/once方法

    function Event() { this._events = {}; } Event.prototype.on = function(type, fn) { if (!this._events[ ...

  3. [置顶] flex4事件监听与自定义事件分发(三)

    1.我们来说一下自定义事件子类.什么时候创建新的事件类以及怎么创建. (1)说一下,我们什么时候需要自定义事件类.举例说明,在flex中事件的基类是Event,而当我们点击某个按钮或者是单击某个组件的 ...

  4. 【转】Flash AS3.0 中的自定义事件

    原文 http://www.cnblogs.com/acpp/archive/2010/10/19/1855670.html package { import flash.events.Event; ...

  5. Struts2 请求数据的自动封装 及 自定义转换器类

    请求数据自动封装: 实现原理:使用了参数拦截器.struts-default.xml中 <interceptor name="params" class="com. ...

  6. Java中使用自定义类封装数组,添加类方法实现数据操作

    1.具体见注释 2.后续或有更新 public class MyArray { private long[] array; private int cnt; // 自定义数组类的元素个数 /** 使用 ...

  7. jQuery封装自定义事件--valuechange(动态的监听input,textarea)之前值,之后值的变化

    jQuery封装自定义事件--valuechange(动态的监听input,textarea)之前值,之后值的变化 js监听输入框值的即时变化 网上有很多关于 onpropertychange.oni ...

  8. Flex事件机制学习-自定义事件实现类间通信 .

    今天,学习Flex自定义事件,可以使两个类通信,定义一个Main类. public class Main extends Sprite     {            public function ...

  9. salesforce 零基础学习(四十八)自定义列表分页之Pagination基类封装 ※※※

    我们知道,salesforce中系统标准列表页面提供了相应的分页功能,如果要使用其分页功能,可以访问http://www.cnblogs.com/zero-zyq/p/5343287.html查看相关 ...

随机推荐

  1. Splay详解

    平衡树实际很简单的 以下讲解都以Luogu P3369 [模板]普通平衡树为例 我不会带指针的Splay,所以我就写非指针型的Splay Splay是基于二叉查找树(bst)实现的 什么是二叉查找树呢 ...

  2. Java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed

    在使用response重定向的时候,报以下错误:Java.lang.IllegalStateException: Cannot call sendRedirect() after the respon ...

  3. [C++ Primer Plus] 零散知识点(一)、输入函数(cin,cin.get,cin.getline等)+string头文件辨析

    本文几乎照搬http://www.cnblogs.com/luolizhi/p/5746775.html博客,只修改了一点点.不知道怎么转发过来,尴尬... 学C++的时候,这几个输入函数弄的有点迷糊 ...

  4. 剑指offer(34)第一个只出现一次的字符

    题目描述 在一个字符串(1<=字符串长度<=10000,全部由字母组成)中找到第一个只出现一次的字符,并返回它的位置 题目分析 只需要用map记录字符出现的次数就行,比较简单的题 代码 f ...

  5. Pandas之分组

    假如我们现在有这样一组数据:星巴克在全球的咖啡店信息,如下图所示.数据来源:starbucks_store_locations.我们想要统计中国每个城市的星巴克商店的数量,那我们应该怎么做呢? 在pa ...

  6. (转载)Unity_3DText穿透场景物体解决

    在unity的3D物体下有一个3DText 物体.这个物体可以在空间坐标中显示文本文字. 如下图: 这个3D Text在场景中的显示会出现穿透3D物体的现象.如图:本来这个hello world 的文 ...

  7. 【Luogu P2664】树上游戏

    Problem Description \(lrb\) 有一棵树,树的每个节点有个颜色.给一个长度为 \(n\) 的颜色序列,定义 \(s(i,j)\) 为 \(i\) 到 \(j\) 的颜色数量.以 ...

  8. Fix Python 3 on Windows error Microsoft Visual C++ 14.0 is required

    Fix Python 3 on Windows error Microsoft Visual C++ 14.0 is required Fix the error for Python 3.6 and ...

  9. Codeforces 40 E. Number Table

    题目链接:http://codeforces.com/problemset/problem/40/E 妙啊... 因为已经确定的格子数目严格小于了$max(n,m)$,所以至少有一行或者一列是空着的, ...

  10. [Windows端口占用] 找到占用端口的进程并杀死

    命令行: netstat -aon|findstr "80" 会得到类似下列的数据 TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 2736 2736代表占用 ...