0
我想要某個功能在人向左或向右滑動時發生,但我不希望該功能在人員沿對角線滑動時執行。有沒有簡單的方法來做到這一點?目前我正在處理以下代碼:如何檢查電暈中的滑動角度SDK
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)
對不起,我寫了{}而不是關鍵字「then」和「end」,我現在正在用JS工作:) –