使用按键事件在我的应用程序中返回。

我尝试了这个代码,但我不知道要“把它放在哪里”:是放在main.lua中还是放在每个level01、level02等等中?

我尝试插入这段代码,但它只能工作一次。我把这段代码放在我的

scene:createScene()

function onBackButtonPressedAtMap(e)
    if (e.phase == "down" and e.keyName == "back") then
        -- 这里按键被按下了
        downPress = true
        return true
    else
        if (e.phase == "up" and e.keyName == "back" and downPress) then
            storyboard.returnTo = "start"
            Runtime:removeEventListener( "key", onBackButtonPressedAtMap)
            return true
        end
    end
    return false
end
Runtime:removeEventListener( "key", onBackButtonPressedAtMap)
点赞
用户1870706
用户1870706

实际上,关键的事件代码应该在 main.lua 中设置,并且只需设置一次。在场景中尝试开启和关闭它会导致太多问题。

Rob

2014-06-09 01:45:36