transition.pause() not working in Composer

transition.to(star,{y=offScreen\*2,time=objSpeed\*speedFactor}) if resume==2 then transition.pause() end -- keeps stars from moving when resuming a game

In the above code I have placed stars on a screen to move off screen at variable rates. If the game is interupted and restarted, a value of 2 for resume is passed to the function that places the stars on screen. When resume==2 the moving stars are stopped after placing them until the game is restarted by tapping a resume button.

This works with storyboard just fine. However the identical code doesn’t work at all with composer. If I use this code in composer the stars never pause, they just keep moving.

Anybody know why this would work in storyboard and not composer???

Thanks,

Guy

Well i have only used storyboard a handfull of times because corona switched to composer so i cant tell you much but lets start

  1. how many transitions do you have in that scene?

  2. maybe instead of transition.pause() try this code>

    transition.to( star, { y = offScreen * 2, time = objSpeed * speedFactor } ) if resume == 2 then transition.pause( star ) end

since i don’t know your resume functions and such i cant tell you much more.

SonicX278, Thanks for trying to help. Yes, I do indeed have lots of transitions. Concerning the “star” object I usually have from 5 to 15 at once on the screen. As you suggested above, I also tried using that very code. It just doesn’t work with Composer, but works well with Storyboard. I’m trying to convert the game from Storyboard to Composer and this is the only problem holding me up with the conversion. It’s very confusing to me why it would work with Storyboard and not Composer???

I had a solution for you but then i looked at your code and saw i meesed up… give me a second…

I’m not aware of any issues with transition.pause() in composer. It could be that the issue is that your check for “resume == 2” is returning false. Here’s a way to find out. Modify your code to this:

transition.to(star,{y=offScreen\*2,time=objSpeed\*speedFactor}) if resume==2 then print("RESUME IS 2. WHAT GIVES, TRANSITION.PAUSE()?!?") transition.pause() -- keeps stars from moving when resuming a game else print("OH, RESUME IS " .. tostring(resume) .. ". STAY CLASSY, TRANSITION.PAUSE().") end

Run your app and check the terminal window. If you see the first print statement (“RESUME IS 2”, etc.) get printed to the terminal, then you know that the problem lies with transition.pause(), but if you see the other print statement, then you know that the problem is that resume is not returning 2. I would wager that it’s a scoping issue, and that resume is returning nil. But the code above will put it to rest for sure.

Good luck!

schroderapps - thanks for trying to help. I had already tried something similar to what you suggested. I used the following code to make sure resume was returning a value of 2:

if resume==2 then transition.pause() print("transition paused!, resume =", resume) end 

The statement with a resume value of 2 always prints, so I know resume has the correct value.

I think I’m going to have to carefully rewrite the entire lua file module and see if it will work. I really don’t want to do that, but it’s starting to look like the only solution.

Hrm. It’s also possible that you can’t cancel a transition in the same moment that you create a transition? Try this:

transition.to(star,{y=offScreen\*2,time=objSpeed\*speedFactor}) if resume==2 then timer.performWithDelay(5, transition.pause) end -- keeps stars from moving when resuming a game

Just a wild guess, but stranger things have happened. I know, for example, that you can’t call composer.removeHidden() in the enterScene method without applying a split-second timer. This might be a similar situation.

The timer.performWithDelay idea sounded good! So, I tried it with 5 and it didn’t work. I tried it again with 50, then 500 and still it doesn’t work. This is indeed a strange problem. 

make a function… that will work in composer…

OK, I tried making the transition pause as a function. I created all the stars, then called the function after all stars had been placed on screen. No go, the transition will still not pause. This is bizarre, same code works in storyboard but not composer…go figure!

Sounds like it’s time for a bug report. Can you package up a simple project folder that exhibits the bug and submit it? I know it’s a pain, but it’s your best bet to get it fixed (it’s also confirmation that it’s not specific to your app).

I’ve been experimenting with solutions for this thread for a while, and I’ve been able to consistently get results with the below code:

local transitionItem2Stash = {} function pauseAllItem1Trans() for i=1, #transitionItem2Stash do transition.pause(transitionItem2Stash[i]) end print("pausing now") end function resumeAllItem1Trans() for i=1, #transitionItem2Stash do transition.resume(transitionItem2Stash[i]) end print("resuming now") end local rectTest = display.newRect(display.contentCenterX, display.contentCenterY, 80,80) local function rotateTest1() local function rotateTest2() transitionItem2Stash[#transitionItem2Stash+1] = transition.to( rectTest, { time=3000, rotation = -360, onComplete=rotateTest1 } ) print("rotating again here") end transitionItem2Stash[#transitionItem2Stash+1] = transition.to( rectTest, { time=3000, rotation = 360, onComplete=rotateTest2 } ) print("rotating first here") end rotateTest1() timer.performWithDelay(4000, pauseAllItem1Trans, 1) timer.performWithDelay(8000, resumeAllItem1Trans, 1)

I can reliably pause and resume transitions in this way. Can you attempt to implement this with your code and see if it has any affect?

Alex@Panc, This looks like an interesting idea to try. I just left home for a few hours, but when I return I’ll try to see if I can implement this idea with my code. Thanks!

The problem is finally solved! Thanks to ideas from SonicX278 and schroederapps.

SonicX278 suggested I try creating a function to pause the stars. So I tried this and it didn’t work.

local function stop() transition.pause() end transition.to(star,{y=offScreen\*2,time=objSpeed\*speedFactor}) if resume==2 then stop() end

Schroederapps suggested I use a timer to delay the transition.pause(). This is what I used and that didn’t work.

transition.to(star,{y=offScreen\*2,time=objSpeed\*speedFactor}) if resume==2 then timer.performWithDelay(1,transition.pause) end

But, when I combined the two ideas it worked! Here’s what I did.

local function stop() transition.pause() end transition.to(star,{y=offScreen\*2,time=objSpeed\*speedFactor}) if resume==2 then timer.performWithDelay(1,stop) end

Thanks everyone for your help!

Guy

Well i have only used storyboard a handfull of times because corona switched to composer so i cant tell you much but lets start

  1. how many transitions do you have in that scene?

  2. maybe instead of transition.pause() try this code>

    transition.to( star, { y = offScreen * 2, time = objSpeed * speedFactor } ) if resume == 2 then transition.pause( star ) end

since i don’t know your resume functions and such i cant tell you much more.

SonicX278, Thanks for trying to help. Yes, I do indeed have lots of transitions. Concerning the “star” object I usually have from 5 to 15 at once on the screen. As you suggested above, I also tried using that very code. It just doesn’t work with Composer, but works well with Storyboard. I’m trying to convert the game from Storyboard to Composer and this is the only problem holding me up with the conversion. It’s very confusing to me why it would work with Storyboard and not Composer???

I had a solution for you but then i looked at your code and saw i meesed up… give me a second…

I’m not aware of any issues with transition.pause() in composer. It could be that the issue is that your check for “resume == 2” is returning false. Here’s a way to find out. Modify your code to this:

transition.to(star,{y=offScreen\*2,time=objSpeed\*speedFactor}) if resume==2 then print("RESUME IS 2. WHAT GIVES, TRANSITION.PAUSE()?!?") transition.pause() -- keeps stars from moving when resuming a game else print("OH, RESUME IS " .. tostring(resume) .. ". STAY CLASSY, TRANSITION.PAUSE().") end

Run your app and check the terminal window. If you see the first print statement (“RESUME IS 2”, etc.) get printed to the terminal, then you know that the problem lies with transition.pause(), but if you see the other print statement, then you know that the problem is that resume is not returning 2. I would wager that it’s a scoping issue, and that resume is returning nil. But the code above will put it to rest for sure.

Good luck!

schroderapps - thanks for trying to help. I had already tried something similar to what you suggested. I used the following code to make sure resume was returning a value of 2:

if resume==2 then transition.pause() print("transition paused!, resume =", resume) end 

The statement with a resume value of 2 always prints, so I know resume has the correct value.

I think I’m going to have to carefully rewrite the entire lua file module and see if it will work. I really don’t want to do that, but it’s starting to look like the only solution.

Hrm. It’s also possible that you can’t cancel a transition in the same moment that you create a transition? Try this:

transition.to(star,{y=offScreen\*2,time=objSpeed\*speedFactor}) if resume==2 then timer.performWithDelay(5, transition.pause) end -- keeps stars from moving when resuming a game

Just a wild guess, but stranger things have happened. I know, for example, that you can’t call composer.removeHidden() in the enterScene method without applying a split-second timer. This might be a similar situation.