android后退按钮不起作用

时间:2014-10-31 02:55:53

标签: android lua cocos2d-x

这些代码在Win32上运行良好,但Android上没有任何反应,任何帮助都会非常感激。

local function onKeyPressed(keycode, event)
        print("key pressed")
        if(keycode == cc.KeyCode.KEY_ESCAPE) then
            cc.Director:getInstance():endToLua()
        end
end

local listener = cc.EventListenerKeyboard:create()
listener:registerScriptHandler(onKeyPressed, cc.Handler.EVENT_KEYBOARD_PRESSED)
scene:getEventDispatcher():addEventListenerWithSceneGraphPriority(listener, scene)

1 个答案:

答案 0 :(得分:0)

- android中的后退按钮

local function onKeyReleased(keyCode, event)
    if keyCode == cc.KeyCode.KEY_ESCAPE then
        cc.Director:getInstance():endToLua()
    end
end

local listener = cc.EventListenerKeyboard:create()
listener:registerScriptHandler(onKeyReleased,cc.Handler.EVENT_KEYBOARD_RELEASED)

local eventDispatcher = self:getEventDispatcher()
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, scene)