transition.cancel(trans) does not work when touch phase is ended

Hi
I am trying to cancel a transition when the touch phase is ended however I am not getting the result that I am expecting. The transition keeps going until it is finished.

Here is my code:
[lua] function touchListener( event )
if event.phase == “began” then
trans = transition.to( ball, { time=1000, alpha=1, x= ball.x, y= ball.y - 200 } )
elseif event.phase == “moved” then
print(“moved”)
elseif event.phase == “ended” then
transition.cancel(trans)
end
end[/lua] [import]uid: 167063 topic_id: 29475 reply_id: 329475[/import]

Hi there,

Your code looks OK to me, so it’s a bit of a puzzle.

One question: do you use the [lua]trans[/lua] variable anywhere else in your code? Since it’s a global variable, if you use it elsewhere in your code (for example, assigning other transitions to it), that would be a problem, because the [lua]trans[/lua] variable might no longer refer to the transition of the ball when you try to cancel it.

If, on the other hand, you don’t use the [lua]trans[/lua] variable anywhere else in your code, then I’m frankly not sure what else the problem could be.

  • Andrew [import]uid: 109711 topic_id: 29475 reply_id: 118338[/import]

Thanks for the reply.

trans is a local variable. I am not using it anywhere in the code. I removed the keyword local to see whether the issue is caused by it. [import]uid: 167063 topic_id: 29475 reply_id: 118343[/import]

Is your touch ending on the exact same object that it began on? If not, you won’t get an ended phase returned (or at least not the correct one), and thus no transition cancellation. For example, if you touch a button, you’ll get the began phase… but if you then move (slide) your touch off, or if the object moves out from under your touch point, when you release there will not be an ended phase.

Maybe this helps?

Brent
[import]uid: 9747 topic_id: 29475 reply_id: 118345[/import]

the touch object is the whole screen, so I assume even if i move after touch event I still should get the end phase.

I made some tests with print() function at the end phase and it is working fine. [import]uid: 167063 topic_id: 29475 reply_id: 118346[/import]

Interesting… that should be working then… and if your print statements are showing the same object ID on began and ended, that proves it. How do initially declare “trans”? This issue seems strange, because logically your code should be working.

Brent
[import]uid: 9747 topic_id: 29475 reply_id: 118348[/import]

Thanks for the input. The function is OK. I solved the issue.
Apparently the issue lied in the event listener line, I moved it to the main.lua file and it worked perfectly.

Thanks again [import]uid: 167063 topic_id: 29475 reply_id: 118363[/import]