consecutive transition.to call result in strange results

I would expect this code to raise a rectangle up along either side of the screen and then traverse across the top ending up in the top center of the screen.

Instead what happens is the rectangle does a sweeping arch from the lower corner of the screen to the upper center of the screen. It’s as if it is combining the two transition.to functions and giving me a “combined” result.

How do I get it to do what I want it to do, instead of what it wants to do.

–this should be when the rectangle then moves toward the center of the screen.
function moveAcross(side)
if side==“R” then
transition.to(r_lift,{delay=500, time=1500,x=_W/2})
else
transition.to(l_lift,{delay=500, time=1500,x=_W/2})
end
end

–this begins the raise of either side of the screen of the rectangles (r_lift /l_lift)
function raiseLift(side)
if side==“R” then
transition.to(r_lift,{delay=1000, time=3000,y=H_cnt, onComplete=moveAcross(“R”)})
else
transition.to(l_lift,{delay=1000, time=3000,y=H_cnt, onComplete=moveAcross(“L”)})
end

end

–this function creates the two rectangles and gives them physics.
function positionLifts()
l_lift=display.newRect(0,_H-5,W_cnt,5)
l_lift.name=“l_lift”
physics.addBody(l_lift,“static”)
localGroup:insert(l_lift)

r_lift=display.newRect(_W-W_cnt,_H-5,W_cnt,5)
r_lift.name=“r_lift”
physics.addBody(r_lift,“static”)
localGroup:insert(r_lift)
end

[import]uid: 50215 topic_id: 12236 reply_id: 312236[/import]

It’s extremely dificult to read your code. Putting it in lua tags would make it much easier.

Could you post the code that is actually calling the functions with transitions in them? If both moveAcross and raiseLift are being called at the same time then the result would indeed be combined in to a single complex transition. If you want one transition to happen after the other completes then you just need to use a timer to wait until the first transition completes before calling the second. [import]uid: 27965 topic_id: 12236 reply_id: 44613[/import]

The oncomplete events are wrong:

onComplete=moveAcross(“R”)})

What this code does is executing moveAcross(“R”) and the result, nil in this case, is asigned to onComplete. Thats to say, the raiselift and moveacross transitions are executed simultaneously and nothing is done when the first ends.

If you want to pass parameters to oncomplete you need to use a auxiliar function that returns a closure.

Take a look at this:

http://blog.anscamobile.com/2011/02/using-closures-in-lua-to-avoid-global-variables-for-callbacks/

Regards,

Isidro [import]uid: 53514 topic_id: 12236 reply_id: 44614[/import]

That blog is really useful, thanks [import]uid: 50215 topic_id: 12236 reply_id: 44636[/import]