Help with transitions

Hi, I’m absolutely new to this. I can code a bit of Jquery (enough to build web interfaces) and PHP, so Corona SDK was easy for me to understand, or at least to read.

I was trying to follow a whack-a-mole tutorial I found somewhere and without reading the code I tried to program it myself.

I wanted to make the moles go up and down and after a bit of searching I went with the transition.to() function with no luck at all.

Then I gave up and went back to the tutorial to see how it was done and I finally got it working. 

The problem I have is understanding why my way didn´t work. Here´s the code.

THIS WORKS:


local function moveMoleDown()             mole1.transition=transition.to(mole1,{ time=500, y=237}) end local function moveMoleUp()             mole1.transition=transition.to(mole1,{ time=500, y=137, onComplete=moveMoleDown}) end moveMoleUp()  

THIS DOESN¨T

            mole2.transition=transition.to(mole2,{ time=500, y=237})             mole2.transition=transition.to(mole2,{ time=500, y=137})  

In the first case I have to build to functions (UP and DOWN) and when the mole is up, I have to call the down function.

In the second case I move the mole UP with a transition but can´t get it DOWN with the same command.

I know this may sound really stupid, but I´m just starting.

Thanks!

Hi @eflouret,

Welcome to Corona! The issue here is that you’re overwriting one transition with another, and Corona only honors the UP transition. If you don’t want to use functions with “onComplete”, you can daisy-chain transitions by separating them with delays. Like this:

[lua]

mole2.transition=transition.to(mole2,{ time=500, y=137})

mole2.transition=transition.to(mole2,{ time=500, delay=500, y=237})

[/lua]

In this case, the second transition will start after the first is completed, so this should send the mole up, then down.

Hope this helps,

Brent Sorrentino

It could be worth pointing out that the code keeps running even though the transitions are not finished. An example:

[lua]transistion.to(mole1, {time= 500, y = 137})
print(“Hello”)[/lua]

The print statement will be shown before the transition is completed. You could see the transition.to as the go-signal.

@Brent, thanks for your reply. Yes, I tried that, but the results are strange with lower delays.

@jensto, that explains everything. I thought the second statement wouldn´t be launched until the first one was ended. So that explains why the delay and time attributes didn´t work as I thought. 

Thanks!

Enrique

Hi @eflouret,

Welcome to Corona! The issue here is that you’re overwriting one transition with another, and Corona only honors the UP transition. If you don’t want to use functions with “onComplete”, you can daisy-chain transitions by separating them with delays. Like this:

[lua]

mole2.transition=transition.to(mole2,{ time=500, y=137})

mole2.transition=transition.to(mole2,{ time=500, delay=500, y=237})

[/lua]

In this case, the second transition will start after the first is completed, so this should send the mole up, then down.

Hope this helps,

Brent Sorrentino

It could be worth pointing out that the code keeps running even though the transitions are not finished. An example:

[lua]transistion.to(mole1, {time= 500, y = 137})
print(“Hello”)[/lua]

The print statement will be shown before the transition is completed. You could see the transition.to as the go-signal.

@Brent, thanks for your reply. Yes, I tried that, but the results are strange with lower delays.

@jensto, that explains everything. I thought the second statement wouldn´t be launched until the first one was ended. So that explains why the delay and time attributes didn´t work as I thought. 

Thanks!

Enrique