在cocos2dx3.X提供了自定义事件。用户可以调用相应API来实现自己所需事件的创建和分发。<p></p><p>以下是如何在lua中使用自定义事件API</p><p>
新建自定义事件</p><pre name="code">--使用事件分发器
local dispatcher = cc.Director:getInstance():getEventDispatcher()
--创建自定义事件
local custom_event = cc.EventCustom:new("event_name")
--分发时间
dispatcher:dispatchEvent(custom_event)
添加自定义事件监听器 local dispatcher = cc.Director:getInstance():getEventDispatcher();
--新建事件监听器
local custom_listener = cc.EventListenerCustom:create("custom", function(event)
--do something
end)
--添加事件监听器到分发器
dispatcher:addEventListenerWithFixedPriority(custom_listener, 1);
本文介绍了如何在Cocos2d-X 3.X版本中使用自定义事件API,包括新建自定义事件、添加事件监听器等步骤,并通过代码示例进行演示。
3989

被折叠的 条评论
为什么被折叠?



