cocos2d-x lua 使用自定义消息EventCustom
cocos2d-x lua 使用自定义消息EventCustom
version: cocos2d-x 3.6
1.发送消息
-- post message
-- event将会被传递给消息接收函数,所以所有需要传递的数据都可放到event中
local event = cc.EventCustom:new("MSG_TEST")
event._usedata = {["state"]=self.curState, ["actionId"]=self.actionId}
cc.Director:getInstance():getEventDispatcher():dispatchEvent(event)
2.监听与接收
- 监听消息需要调用
self:enableNodeEvents()使消息接收有效
-- listener
local ActorSprite = class("ActorSprite", cc.Node)
function ActorSprite:initEventListener()
self:enableNodeEvents() -- cc.Node
self.eventListeners = {} -- user to delete when dtor
local listener = cc.EventListenerCustom:create(MSG_TEST, handler(self, self.onChangeState))
local eventDispatcher = self:getEventDispatcher()
eventDispatcher:addEventListenerWithFixedPriority(listener, 1)
table.insert(self.eventListeners, listener)
end
function DogSprite:onChangeState(event)
local dogId = event._usedata["dogId"]
local actionId = event._usedata["actionId"]
local eventName = event:getEventName()
end
return ActorSprite
3.清理
- 在ActorSprite被释放之后,需要将监听删除,否则收到消息后self为nil,将会导致异常(onCleanup将会在节点被删除时自动调用)。
function ActorSprite:onCleanup() -- cc.Node
for i, var in ipairs(self.eventListeners) do
cc.Director:getInstance():getEventDispatcher():removeEventListener(var)
end
end
cocos2d-x lua 使用自定义消息EventCustom的更多相关文章
- 使用cocos2d脚本生成lua绑定
这几天要老大要求把DragonBones移到cocos2dx 3.0 里边,并且绑定lua使用接口.因为刚学lua,使用的引擎也刚从2.2改为3.0,各种不熟悉,折腾了好几天才弄完,有空了总结一下 这 ...
- 《Cocos2d-x实战 Lua卷》上线了
感谢大家一直以来的支持!各大商店均开始销售:京东:http://item.jd.com/11659697.html当当:http://product.dangdang.com/23659810.htm ...
- 【转】cocos2d-x Lua
Call custom c++ from Lua cocos2d-x lua binds c++ class, class functions ,enum and some global functi ...
- Cocos2d-x3.0下一个 Lua与C++打电话给对方
这里谈下Lua与C++如何实现相互通话 原来的连接:http://blog.csdn.net/qqmcy/article/details/26052771 DJLCData.h 实现类 // // D ...
- cocos2dx 3.3 C++工程添加lua支持
准备工作: 1. 拷贝cocos2d-x-3.3rc0\external\lua整个文件夹到项目中(如myProject\cocos2d\external\lua) 2. 拷贝cocos2d-x-3. ...
- xcode 运行 lua版本崩溃 解决方案
问题描述:运行到LuaStack::init() 崩溃 原因: luajit不支持arm64 解决方案:编译luajit64位静态库 a.可以直接下载别人编译好的库,然后直接覆盖cocos2d\ext ...
- 游戏人生(一),我的lua之旅:那些坑爹的CCBReaderLoad
首先,我们说说这个CCBReaderLoad. 这个脚本是cocos2dx自带的一个lua+cocosbuilder 的工具,详细功能呐,往下看. 先来看下我遇到的一个问题: ----美工给了我一个. ...
- Cocos2d-x 核心概念 - 坐标系(UI.OpenGL.世界坐标系.模型坐标系)
UI坐标系与OpenGL坐标系 UI坐标就是Android和IOS等应用开发时候使用的二维坐标系,原点在左上角 OpenGL坐标是三维坐标,由于Cocos2d-x Lua 底层采用OpenGL渲染,因 ...
- Skynet Pomelo Erlang Elixir 的认识
1.skynet pomelo(node.js) elixir(erlang) 周末研究总结 手游这两年发展来看,感觉对实时性要求越来越高,有同事在研究Elixir开发,google得知这东西是基于e ...
随机推荐
- Codeforces Round #364
http://codeforces.com/contest/701 A - Cards 水 // #pragma comment(linker, "/STACK:102c000000,102 ...
- 安装 RabbitMQ C#使用-摘自网络(包括RabbitMQ的配置)
1.什么是RabbitMQ.详见 http://www.rabbitmq.com/ . 作用就是提高系统的并发性,将一些不需要及时响应客户端且占用较多资源的操作,放入队列,再由另外一个线程,去异步处理 ...
- JSF 2 textarea example
In JSF, you can use the <h:inputTextarea /> tag to render a HTML textarea field. For example, ...
- AVCaptureDevice的几个属性
AVCaptureDevice.h,主要用来获取iphone一些关于相机设备的属性. AVCaptureDevice.h,必须要引入AVFoundation.framework包. 1. 前置和后置摄 ...
- POJ3630Phone List(字典树)
参考http://s.acmore.net/show_article/show/58 以附上代码 #include<iostream> #include<stdio.h> #i ...
- window 下cygwin开启了后来又关闭了
特征: ssh localhost 出现port 27 拒绝访问等 系统日志记录信息: 事件 ID ( 0 )的描述(在资源( sshd )中)无法找到.本地计算机可能没有必要的注册信息或消息 DLL ...
- web config数据库连接字符串加密
ASP.NET web.config中,数据库连接字符串的加密与解密 ASP.NET web.config中,数据库连接字符串的加密与解密. 开始--->运行,输入cmd,接着输入以下内容 加密 ...
- How Much Work Does it Take to be a Successful Mathematician?
http://mathoverflow.net/questions/9799/how-much-work-does-it-take-to-be-a-successful-mathematician# ...
- springMVC部署
一.导入springMVC所需要的jar包 下载地址:http://repo.spring.io/release/org/springframework/spring/ 二.springM ...
- Converting a .jks Key Store to a .pem Key Store
In order to convert a Java key store into a Privacy Enhanced Mail Certificate, you will need to use ...