【问题标题】:How to check the angle of a swipe in corona SDK如何在电晕 SDK 中检查滑动的角度
【发布时间】:2017-07-18 01:09:29
【问题描述】:

我希望在一个人向右或向左滑动时执行某个功能,但我不希望在一个人对角滑动手指时执行该功能。有没有一种简单的方法可以做到这一点?目前我正在使用此代码:

display.setDefault("background", 0.2, 0.2, 0.4 )

local function startDrag(event)
    local swipeLength = math.abs(event.x - event.xStart) 
    print(event.phase, swipeLength)
    local t = event.target
    local phase = event.phase
    if "began" == phase then
        return true
    elseif "moved" == phase then
    elseif "ended" == phase or "cancelled" == phase then
        if event.xStart > event.x and swipeLength > 50 then 
            display.setDefault("background", 0/255,3/255, 0/255 )
        elseif event.xStart < event.x and swipeLength > 50 then 
            display.setDefault("background", 0, 0, 1 )
        end 
    end
end

local rectangle= display.newRect(100,200,1000,1000)
rectangle:setFillColor(1,1,1,0.1)
rectangle:addEventListener("touch",startDrag)

【问题讨论】:

    标签: lua coronasdk


    【解决方案1】:

    当事件阶段“结束”时,我还会检查 y 位置。例如,

    if (event.y - 5 <= event.yStart and event.y + 5 >= event.yStart) then
    
       -- almost perfect line, 
       -- if someone draws a line from bottom-left to top-right, it won't work
    end
    

    您可以测试并将 5 或 -5 更改为适合您的值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 2013-07-15
      • 1970-01-01
      • 1970-01-01
      • 2011-10-05
      • 1970-01-01
      • 2017-03-19
      相关资源
      最近更新 更多