lua - 手动结束或取消corona sdk中的触摸阶段?

标签 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("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)

关于lua - 手动结束或取消corona sdk中的触摸阶段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19780069/

相关文章:

lua - 为什么Lua中是 `local print = print`?

lua gsub %b <-- 这是如何工作的?

unity3d - Unity3D中OnPointerDown与OnBeginDrag的恐怖

lua - Corona SDK 中的水平 ScrollView

android - windows环境下在corona中使用InputTextBox

c# - Lua的跨平台C#实现

for-loop - Lua 中的奇怪 "attempt to call a table value"

ios - 绘图后如何分隔圆点

html - 触摸屏的CSS伪类问题

android - 如何删除 corona sdk 启动画面周围的粉红色边框?