cocos2d-x lua 调用onEnter和onExit
version: cocos2d-x 3.6
onEnter和onExit在lua中不会因节点别add和remove而直接被调用,当子节点被父节点add和remove时,会发送enter和exit的消息,所以需要再初始化节点的时候,监听消息,并在收到消息后调用onEnter或onExit。
local function onNodeEvent(event)
if event == "enter" then
self:onEnter()
elseif event == "exit" then
self:onExit()
end
end
self:registerScriptHandler(onNodeEvent)