cocos2d-x3.x自定义事件

时间:2023-03-09 06:57:44
cocos2d-x3.x自定义事件

-- 自定义事件
-- 监听:

local eventDispatcher = self:getEventDispatcher();--self为继承Node的对象

local function handleBuyGoods(event)
cclog("handleBuyGoods")
end
local listener = cc.EventListenerCustom:create("HandleKey.kDidBuyGoods", handleBuyGoods)
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, self)

-- 广播:

local eventDispatcher = cc.Director:getInstance():getEventDispatcher()
local event = cc.EventCustom:new("HandleKey.kDidBuyGoods")
eventDispatcher:dispatchEvent(event)

--事件机制入口:http://www.cnblogs.com/haogj/p/3784896.html