在Corona中从native.showalert更改场景

我在我的游戏中有一个返回按钮。它有一个名为btnTap的点击事件。点击后会弹出一个警告,用户会有两个选项,去“luduMenu”场景还是继续玩游戏。但是它不起作用,当我点击是时场景仍然保持不变。这是我尝试的代码。

local onComplete = function ( event )
  if "clicked" == event.action then
    local i = event.index
    if 1 == i then
        -- 什么也不做;对话框将简单地关闭
        system.setIdleTimer( true )
        storyboard.gotoScene (  "luduMenu" )

    elseif 2 == i then
        -- 如果单击了“Learn More”(第二个按钮),则打开URL

    end
  end
end

-- 在此应放置本地前向引用 --
local function btnTap(event)
  local alert1 = native.showAlert( "返回",  "确定吗?", { "是", "否" }, onComplete )
  return true
end
点赞
用户1936710
用户1936710

我通过从场景的 exisitevent 中移除以下行来解决问题

storyboard.purgeScene("onevsone")

并且像下面这样排列代码

local function btnTap(event)
    local function onAlertComplete(event)
      if "clicked" == event.action then
        local i = event.index
        if i == 1 then
            storyboard.gotoScene("luduMenu")
        end
      end
    end

    native.showAlert( "End Game?", "Are you sure you want to exit this game?", { "Yes", "No" }, onAlertComplete )
    return true
end
2014-03-15 17:41:40