every time a new transition

some troubles again(

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 )

try declaring char_tween outside WalkToTapPos
and giving transition.cancel(char_tween)

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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 )

good... just a suggestions. local char_tween
will do the job. you don't have to declare it as an array.

views:1407 update:2011/9/27 18:14:54
corona forums © 2003-2011