2

The touch event in Corona has 4 phases: "began", "moved" , "ended" and "cancelled". When does the event receive the "cancelled" phase? (I didn't find a function that you can cancel the event with it, you can just remove the listeners). And how can I use the "cancelled" event phase in application?

TatianaCooper
  • 155
  • 2
  • 13

2 Answers2

1

Corona SDK is an abstraction layer upon the top of iOS and Android; most design decisions will reflect upon the underlying platform.

It would seem the touch event implements the UITouch object (and whatever the equivalent is on Android). Searching Google for "iphone uitouch cancelled" resulted in this question, which should answer yours.

If you need to manually "cancel" an event, simply store a flag in an associated object (or in the touch event, if it's a simple table) and check it when "moved" or "ended" is called.

(Disclaimer: I have never used Corona, nor developed for mobile platforms.)

Community
  • 1
  • 1
Deco
  • 5,112
  • 1
  • 16
  • 17
1

Basically if you are holding an object, button, etc. and you slide your finger off instead of releasing it that will be registered as 'canceled' which you can do what you wish with, usually the same as 'ended'

Example:

if event.phase == "began" then --Pressing the button
   move = true
elseif event.phase == "canceled" then --sliding your finger off
   move = false
elseif event.phase == "ended" then --Releasing the button
   move = false
end
Krystian
  • 71
  • 14
  • "usually the same as 'ended'", wouldn't agree. In your example that's, true, but one of the most common things to use it for is to track a click on an object. In that case it is usually better to just ignore that event – Henrik Karlsson Jun 28 '14 at 17:09