Lua 在corona sdk中手动结束或取消触摸阶段?

Lua 在corona sdk中手动结束或取消触摸阶段?,lua,touch,coronasdk,Lua,Touch,Coronasdk,是否可以手动取消或结束对象上的触摸阶段?我基本上想让用户不可能拖动对象,除非他们把手指从屏幕上拿开,然后再次开始拖动。这可能吗 local isDragAllowed = 0 -- create a flag or a variable local bg = display.newRect(0,0,display.contentWidth,display.contentHeight) -- background local myObject = display.newImageRect("

是否可以手动取消或结束对象上的触摸阶段?我基本上想让用户不可能拖动对象,除非他们把手指从屏幕上拿开,然后再次开始拖动。这可能吗

local isDragAllowed = 0  -- create a flag or a variable

local bg = display.newRect(0,0,display.contentWidth,display.contentHeight) -- background

local myObject = display.newImageRect("Icon.png", 50, 50); -- your object
myObject.x = 160
myObject.y = 240

local function touchHandler(event)
    if(event.phase=="began")then
        isDragAllowed = 1
    elseif(event.phase=="moved" and isDragAllowed==1)then
        -- object will be moved only if the flag is true or 1
        myObject.x = event.x
        myObject.y = event.y
    else
        isDragAllowed = 0 -- resetting the flag on touch end
    end
    return true;
end
myObject:addEventListener("touch",touchHandler)

local function bgTouchHandler(event)
    print(event.phase)
    isDragAllowed = 0 -- resetting the flag if drag/touch happens on background
    return true;
end
bg:addEventListener("touch",bgTouchHandler)

继续编码。。。。。。。。。。。。您可以通过添加flag以一种简单的方式来完成。我将如何进行此操作?对不起,关于我的问题。我真是个笨蛋。哦,我明白了!非常感谢你!