【问题标题】:Restricting touch events in corona限制电晕中的触摸事件
【发布时间】:2013-03-17 05:17:32
【问题描述】:

我的班级上有一个按钮,可以将用户从一个场景带到另一个场景,例如从主菜单到游戏页面。现在,这工作正常,但我想限制触摸。就像,如果我触摸按钮然后拖动,那么我的过渡将不起作用,但如果我触摸按钮并放手它应该可以工作。我该如何实施?这是我的代码目前的样子,但它不起作用:

    if event.phase == "moved" then
    print("cannot be")
elseif event.phase == "began" then
    if event.phase == "ended" then
                storyboard.gotoScene("Game", "fade", 400)
    end
end

如何限制触摸事件?就像如果我触摸按钮,在屏幕上拖动并结束对按钮的触摸,它不应该转换到下一个场景?

【问题讨论】:

    标签: lua coronasdk


    【解决方案1】:

    您应该尝试tap 而不是touch。如下:

     local function sceneChangeFunction()
         storyboard.gotoScene("Game", "fade", 400)
     end
     Runtime:addEventListener("tap",sceneChangeFunction)
    

    如果你想使用touch 本身,那么你可以这样做:

     local sceneChangeFlag = false  -- create a flag, make it false
     local function sceneChangeFunction(e)
         if(e.phase=="began")then
             sceneChangeFlag = true           -- make it true in touch began
         elseif(e.phase=="moved")then
             sceneChangeFlag = false          -- make it false in touch moved
         else
             if(sceneChangeFlag==true)then    -- scene changes only if flag==true 
                 sceneChangeFlag = false
                 storyboard.gotoScene("Game", "fade", 400)     
             end
         end
     end
     Runtime:addEventListener("touch",sceneChangeFunction)
    

    继续编码..... :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-16
      • 1970-01-01
      • 2012-04-03
      • 1970-01-01
      相关资源
      最近更新 更多