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. Redis setnx命令 分布式缓存

    setnx命令 将 key 的值设为 value,当且仅当 key 不存在. 若给定的 key 已经存在,则 SETNX 不做任何动作. SETNX 是SET if Not eXists的简写. re ...

  2. Qt下拉对话框 ComboBox的用法

    介绍 ComboBox是Qt的下拉菜单的一个控件,通过下拉菜单选择不同的选项,样式如图: 基本用法 m_ComBox = ui.comboBox; //设置默认显示值的索引,从0开始 m_ComBox ...

  3. Linux下postgres9.4 版本的单机版安装小笔记

    1.添加RPMyum install https://download.postgresql.org/pub/repos/yum/9.4/redhat/rhel-7-x86_64/pgdg-redha ...

  4. jstack生成的Thread Dump日志线程 分析

    文章转载自: https://www.javatang.com/archives/2017/10/25/36441958.html 前面文章中只分析了Thread Dump日志文件的结构,今天针对日志 ...

  5. C#时间戳的简单实现

    Introduction: 在项目开发中,我们都经常会用到时间戳来进行时间的存储和传递,最常用的Unix时间戳(TimeStamp)是指格林尼治时间1970年1月1日0时(北京时间1970年1月1日8 ...

  6. [hdu P4081] Qin Shi Huang’s National Road System

    [hdu P4081] Qin Shi Huang’s National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Li ...

  7. 2015-10-13 jQuery5实例

    jQuery(5)   一.扑克牌切换 <body> <div class="ig ig1"><img src="image/1.jpg&q ...

  8. centos7系统运行级别简介

    centos7系统运行级别简介我们知道,centos6及之前的版本中,系统运行级别通过/etc/inittab文件进行设置和控制,但在centos7中,对这个文件的设置将不会对系统运行级别产生影响,这 ...

  9. 使用js实现思维导图

    使用js实现思维导图 demo:http://rockyren.github.io/mindmaptree/ 源码:http://github.com/RockyRen/mindmaptree/tre ...

  10. Go used as value问题

    练习Go变参时遇到一个报错:used as value 代码如下: // 错误代码 func myfunc(arg ...int) { for _, n := range arg { fmt.Prin ...