cocos2d-x+lua开发,如何重载scene的事件

CCNode:registerScriptHandler() register callback function for onEnter/onExit events。Callback function auto unregister after onExit() called.

local function createScene()
    local scene = CCScene:node()

    local function sceneEventHandler(eventType)
        if eventType == kCCNodeOnEnter then
            if scene.onEnter then scene:onEnter() end
        else
            if scene.onExit then scene:onExit() end
        end
    end

    scene:registerScriptHandler(sceneEventHandler)

    return scene
end

local scene = createScene()
function scene:onEnter()
    print("on scene enter")
end
fucntion scene:onExit()
    print("on scene exit")
end

CCDirector:sharedDirector():runWithScene(scene)

在cocos2d-x框架中并没有提供继承类的解决方案(在这点上做的功夫远不如iphonewax)

但是呢cocos2d-x在开发游戏上绝对是一个很不错的框架。

下边是官方给出的“重载”事件函数的方法


你可能感兴趣的:(lua,脚本,cocos2d-x)