transition.to onComplete confusion

Please help with my confusion, I’m new to corona.

I have the following very simplified code.

local rect = display.newRect( 100, 100, 50, 50 ) rect:setFillColor(255, 255, 255) function tweenEvent(event) print (event) end transition.to(rect, {delay = 2000,time=2000 , x= -20, delta = true, onStart = tweenEvent("onStart"), onComplete = tweenEvent("onComplete")}) 

The code outputs immediately

onStart

onComplete

I expected the onComplete to be delayed by 4 seconds.

Have I found a bug? or is this how its supposed to operate (the documentation implies otherwise).

my corona version is 2013.1135 (2013.6.3)

When you pass a function as a parameter, you should pass it without the parenthesis. If you use the parenthesis, Lua thinks that you are calling that function.

So, instead of using

transition.to(rect, {delay = 2000,time=2000 , x= -20, delta = true, onStart = tweenEvent("onStart"), onComplete = tweenEvent("onComplete")})

you should use

transition.to(rect, {delay = 2000,time=2000 , x= -20, delta = true, onStart = tweenEvent, onComplete = tweenEvent})

The transition will pass a default param to the function that you are calling, so your onComplete function should be defined as

local function tweenEvent(params) 'your function code here end function

I don’t know if that params has a information that you can use to identify if it was called by the onStart or by onComplete event. If not, just break your function in two functions (one for onStart, one for onComplete).

Renato

Thanks, that solved it, I now get an event a 2 seconds and 4 seconds

When you pass a function as a parameter, you should pass it without the parenthesis. If you use the parenthesis, Lua thinks that you are calling that function.

So, instead of using

transition.to(rect, {delay = 2000,time=2000 , x= -20, delta = true, onStart = tweenEvent("onStart"), onComplete = tweenEvent("onComplete")})

you should use

transition.to(rect, {delay = 2000,time=2000 , x= -20, delta = true, onStart = tweenEvent, onComplete = tweenEvent})

The transition will pass a default param to the function that you are calling, so your onComplete function should be defined as

local function tweenEvent(params) 'your function code here end function

I don’t know if that params has a information that you can use to identify if it was called by the onStart or by onComplete event. If not, just break your function in two functions (one for onStart, one for onComplete).

Renato

Thanks, that solved it, I now get an event a 2 seconds and 4 seconds