按下返回键监听
function FightScene:onKeyboard(code, event)
if code == cc.KeyCode.KEY_BACK then
print("按下返回键")
GameApp:enterScene("MainScene");
end
end
function FightScene:onEnter()
self.keyListener = cc.EventListenerKeyboard:create()
--handler(self,self.onKeyboard)用来关联方法,如果方法直接放在当前位置则可以直接使用无需handler
self.keyListener:registerScriptHandler(handler(self,self.onKeyboard),cc.Handler.EVENT_KEYBOARD_RELEASED)
local eventDispatch = self:getEventDispatcher()
eventDispatch:addEventListenerWithSceneGraphPriority(self.keyListener,self)
end