Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua 限制电晕中的触摸事件_Lua_Coronasdk - Fatal编程技术网

Lua 限制电晕中的触摸事件

Lua 限制电晕中的触摸事件,lua,coronasdk,Lua,Coronasdk,我在我的类上有一个按钮,可以将用户从一个场景带到另一个场景,就像从主菜单带到游戏页面一样。现在,这工作正常,但我想限制触摸。比如,如果我触摸按钮然后拖动,那么转换将不起作用,但是如果我触摸按钮并放开,它应该会起作用。我如何实现这一点?这是我的代码当前的外观,但它不起作用: if event.phase == "moved" then print("cannot be") elseif event.phase == "began" then if event.phase =

我在我的类上有一个按钮,可以将用户从一个场景带到另一个场景,就像从主菜单带到游戏页面一样。现在,这工作正常,但我想限制触摸。比如,如果我触摸按钮然后拖动,那么转换将不起作用,但是如果我触摸按钮并放开,它应该会起作用。我如何实现这一点?这是我的代码当前的外观,但它不起作用:

    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

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

您应该尝试
点击
,而不是
触摸
。详情如下:

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

如果您想使用
触摸
本身,则可以按如下操作:

 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)
继续编码…:)