every time a new transition

some troubles again(

WalkToTapPos = function( event )  
 --Positions  
 local P1 = {}  
 local P2 = {}  
 P1.x, P1.y = math.ceil( char\_walk.x ), math.ceil( char\_walk.y )  
 P2.x, P2.y = math.ceil( event.x ), math.ceil( event.y )  
  
 --Compute s=Weg  
 local kat\_a = P2.x - P1.x  
 local kat\_b = P2.y - P1.y  
  
 local s = math.sqrt( kat\_a^2 + kat\_b^2 ) --Quadrieren, Addieren und Wurzel berechnen  
  
 --v=Geschwindigkeit (Pixel/Seconds)  
 local v = 50/1 --AJUST SPEED HERE!!  
  
 --t=Zeit (Weg/Geschw.)  
 local t = s/v  
  
 print( "You've tapped. Char will move from: x=" .. P1.x .. ", y=" .. P1.y .. " to: x=" .. P2.x .. ", y=" .. P2.y )  
  
 local char\_tween = transition.to( char\_walk, { time = t\*1000, x = P2.x, y = P2.y } )  
end  
Runtime:addEventListener( "tap", WalkToTapPos )  

I “Tap” and the Transition.to() plays.
When I “Tap” again (but the transition is not ready yet) a new transition plays and then weirdly jumps back to the first one, and completes that. How to fix that?
It should actually work, because every movement is computed every time, when tap event happens. [import]uid: 73502 topic_id: 13383 reply_id: 313383[/import]

try declaring char_tween outside WalkToTapPos
and giving [lua]transition.cancel(char_tween)[/lua] [import]uid: 71210 topic_id: 13383 reply_id: 49111[/import]

I guess I was too tired :slight_smile: Thanks, works like a charm!

[code]
local char_tween = {}

WalkToTapPos = function( event )
–Stop everything first(!)
transition.cancel( char_tween )

–Positions
local P1 = {}
local P2 = {}
P1.x, P1.y = math.ceil( char_walk.x ), math.ceil( char_walk.y )
P2.x, P2.y = math.ceil( event.x ), math.ceil( event.y )

–Compute s=Weg
local kat_a = P2.x - P1.x
local kat_b = P2.y - P1.y

local s = math.sqrt( kat_a^2 + kat_b^2 ) --Quadrieren, Addieren und Wurzel berechnen

–v=Geschwindigkeit (Pixel/Seconds)
local v = 50/1 --AJUST SPEED HERE!!

–t=Zeit (Weg/Geschw.)
local t = s/v

print( “You’ve tapped. Char will move from: x=” … P1.x … “, y=” … P1.y … " to: x=" … P2.x … “, y=” … P2.y )

–Play Animation
char_tween = transition.to( char_walk, { time = t*1000, x = P2.x, y = P2.y } )
end
Runtime:addEventListener( “tap”, WalkToTapPos )
[/code] [import]uid: 73502 topic_id: 13383 reply_id: 49186[/import]

good… just a suggestions. [lua]local char_tween [/lua]
will do the job. you don’t have to declare it as an array. [import]uid: 71210 topic_id: 13383 reply_id: 49191[/import]