The touch phase "moved" is not receive.

Hello,everybody,

I am encounter difficulties.

local Fire = display.newImageRect(“fire.png”,90,90) 

local function FireFrame()

   print(“Fireuse”)

end

local function TouchFire(event)

    if event.phase == “began” then

          Runtime:addEventListerner(“enterFrame”,FireFrame)

    elseif  event.phase == “moved” then

         if event.x >= Fire.x - 45 or event.x >= Fire.x + 45 or event.y <= Fire.y - 45 or event.y >= Fire.y + 45 then

              Runtime:removeEventListerner(“enterFrame”,FireFrame)

         end

     else

           Runtime:removeEventListerner(“enterFrame”,FireFrame)

     end

end

Fire:addEventListener(“touch”,TouchFire)

But when I fast touch over the moved condition , No trigger the Runtime:removeEventListerner(“enterFrame”,FireFrame).

I  think I have not continued monitoring because my contact left Fire.

So I changed the condition from 45 to 40 but the situation is still.

If you leave Fire then you should execute “cancelled” but there is no.

How can I solve this problem?

Thank you.


您好 我所遇到的問題是 我的圖片是90,90的大小 

我希望我在圖片上都會執行Frame,離開時則會取消Frame的監控

但當我的手指快速離開時他並沒有執行moved的條件.

請問我該如果解決此問題呢

謝謝您

If that’s the same code as in your project, your app will crash because you’ve written “Listerner” in both “addEventListener” and “removeEventListener”.

Also, your conditions for removing the runtime seem to be wrong. Now you are always deleting the runtime as soon as you move at all. The correct conditions (for an object, regardless of its size) would be:
 

if event.x \<= Fire.x-Fire.width\*0.5 or event.x \> Fire.x+Fire.width\*0.5 or event.y \> Fire.y+Fire.width\*0.5 or event.y \< Fire.y-Fire.width\*0.5 then Runtime:removeEventListener("enterFrame",FireFrame) end

Now, the reason why you are having trouble here is because the touch event only runs while you are touching your object, Fire. If you move your finger (or mouse) too fast between frames, the touch event does not understand that you’d still want to track the touch. You should read https://docs.coronalabs.com/tutorial/events/continuousActions/index.html for advice on how to set up proper continuous action for your button.  

Thanks you XeduR.

I use the answer,and I try to use a TouchObject .

The TouchObject is bigger than the button. 

After that I used a lot of tests and the error no longer exists.

If that’s the same code as in your project, your app will crash because you’ve written “Listerner” in both “addEventListener” and “removeEventListener”.

Also, your conditions for removing the runtime seem to be wrong. Now you are always deleting the runtime as soon as you move at all. The correct conditions (for an object, regardless of its size) would be:
 

if event.x \<= Fire.x-Fire.width\*0.5 or event.x \> Fire.x+Fire.width\*0.5 or event.y \> Fire.y+Fire.width\*0.5 or event.y \< Fire.y-Fire.width\*0.5 then Runtime:removeEventListener("enterFrame",FireFrame) end

Now, the reason why you are having trouble here is because the touch event only runs while you are touching your object, Fire. If you move your finger (or mouse) too fast between frames, the touch event does not understand that you’d still want to track the touch. You should read https://docs.coronalabs.com/tutorial/events/continuousActions/index.html for advice on how to set up proper continuous action for your button.  

Thanks you XeduR.

I use the answer,and I try to use a TouchObject .

The TouchObject is bigger than the button. 

After that I used a lot of tests and the error no longer exists.