"Cancelled" not working?

Hey guys, i just started today with Corona, i was used to work with Lua+Löve and wanted to take the jump on Android so i decided to use Corona.

I’ve had tons of problems as u would imagine beeing a newbie, but i found the answers for most of them, except this one, im trying to make a guy move in 4 directions when pressing and holding the side of the screen.

The thing is, when is “swipe” to the middle (outside the button) and release (i understand that’s a cancellation) it will keep moving, if i release the button on the button region it will stop perfectly, but if i swipe outside the area it will keep going until i come and tap again on the button.

It seems like cancelled is doing nothing, also i tried to “limit” the area to make it stop when the event.x(or y) is outside the event.target.x(or y) and it doesnt seem to work either.

Here’s a little piece of code for the Right side of the screen:

local function buttonR(event) if event.phase == "began" then buttonR = true elseif event.phase == "ended" or event.phase == "cancelled" then --if event.x\<event.target.x then print("OUTSIDE") end if event.phase == "cancelled" then print("CANCELLED") end if event.phase == "ended" then print("ENDED") end buttonR = false end return true end

The prints are my controls on the console, the ENDED prints perfectly, but so far i got 0 CANCELLED prints, am i doing something wrong?

I have no problem on posting the full code or the main.lua or .zip for you guys to try, i would like some tips to make it work, also i prefer the cancelled working than the region limitation, since cutting the movement as soon as u leave the region seems bad, instead allowing u to move it until u release (end or cancel) seems better.

Thanks for your help and excuse my english.

Happy coding :slight_smile:

Edit: added the code into <code>

hi!

check typo error : “cancelled” not “canceled”

burhan

Yeah i changed from cancelled to canceled some times trying to see if that fixed it (some places on internet said canceled and some cancelled) i’m sure that’s not the problem, but i will edit it to avoid confusion (the canceled there was on a control print, it should work even if its not printing anything) 

Thanks for your reply 

To my understanding, “cancelled” will not be called from releasing touch. Only “ended” phase.

“cancelled” is called when the system stop tracking the touch.

I don’t really get what you want but maybe you should  try setFocus()

local function buttonR( event ) local object = event.target if ( event.phase == "began" ) then display.getCurrentStage():setFocus( object ) buttonR = true elseif ( event.phase == "ended" or event.phase == "cancelled" ) then display.getCurrentStage():setFocus( nil ) buttonR = false end return true end

burhan

I love you :smiley: thats exactly what i wanted, it worked like a charm. Thank you so much, im still a bit confused about that focus thing.

Im sorry for my bad explanation, but it is working now and its thank to you, if u’re interested on what im doing i could show u :slight_smile:

Thanks again!.

hi!

check typo error : “cancelled” not “canceled”

burhan

Yeah i changed from cancelled to canceled some times trying to see if that fixed it (some places on internet said canceled and some cancelled) i’m sure that’s not the problem, but i will edit it to avoid confusion (the canceled there was on a control print, it should work even if its not printing anything) 

Thanks for your reply 

To my understanding, “cancelled” will not be called from releasing touch. Only “ended” phase.

“cancelled” is called when the system stop tracking the touch.

I don’t really get what you want but maybe you should  try setFocus()

local function buttonR( event ) local object = event.target if ( event.phase == "began" ) then display.getCurrentStage():setFocus( object ) buttonR = true elseif ( event.phase == "ended" or event.phase == "cancelled" ) then display.getCurrentStage():setFocus( nil ) buttonR = false end return true end

burhan

I love you :smiley: thats exactly what i wanted, it worked like a charm. Thank you so much, im still a bit confused about that focus thing.

Im sorry for my bad explanation, but it is working now and its thank to you, if u’re interested on what im doing i could show u :slight_smile:

Thanks again!.