cocos2d-x lua 調用onEnter和onExit


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)

在創建該節點時,加入上面的代碼,那么onEnter和onExit就會在節點被add和remove是調用了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM