Scale up, then back down

I’m trying to get my text to double in size, then shrink back down, for some reason the transition inside the shrinkText function isn’t working:

local text = display.newText("Text", 100, 100, "helvetica", 20) local function shrinkText() transition.to(text, {time = 2000, xScale = 0.5, yScale = 0.5}) end transition.to(text, {time = 2000, xScale = 2, yScale = 2, onComplete = shrinkText()})

Additionally, any print statements I put in the shrinkText function are executed before the bottom transition is finished. Why does that happen?

transition.to(text, {time = 2000, xScale = 2, yScale = 2, onComplete = shrinkText } )

Take the () off of the function name.  The onComplete needs the address of the function, not the value returned from it.  When you put the () on, it says run the function now and take the results that are returned and assign it to onComplete.   That’s why your function runs right away.  Since the function returns nothing, a nil gets assigned to the onComplete, so the real transition looks like this:

transition.to(text, {time = 2000, xScale = 2, yScale = 2, onComplete = nil })

And therefore when it completes, it has nothing to do.

Rob

Excellent, thanks!

transition.to(text, {time = 2000, xScale = 2, yScale = 2, onComplete = shrinkText } )

Take the () off of the function name.  The onComplete needs the address of the function, not the value returned from it.  When you put the () on, it says run the function now and take the results that are returned and assign it to onComplete.   That’s why your function runs right away.  Since the function returns nothing, a nil gets assigned to the onComplete, so the real transition looks like this:

transition.to(text, {time = 2000, xScale = 2, yScale = 2, onComplete = nil })

And therefore when it completes, it has nothing to do.

Rob

Excellent, thanks!