chyman,
I have a quick fix for you. (keep in mind i am not that experienced with composer myself). So there are probably better(more efficient ) ways to do this. But, this will work.
- When you leave scene2, let’s say you go to menu scene; in the menuScene ‘scene:show’ insert this line of code :
composer.removeScene(“scene2”)
- In scene2, the ‘scene:destroy’ function, be sure to cancel all timers and transitions. This is a little tricky since you need to make sure that none of them are ‘nil’ if you attempt to cancel them. It looks like you have 4 timerPerformWithDelay calls, and at least one transiton.to call. Cancel them all. You may have to do some if checks like so:
if timer1 ~= nil then
timer.cancel(timer1)
end
* you will also have to assign the variable/handle to each of those timerPerformWithDelay calls as such
timer1 = timer.performWithDelay…
timer2 = timer.performWithDelay… etc…
so you will have a way of identifying which timers to cancel
- When menu or any other scene calls ‘goto’ scene2 it will re-create scene2 from scratch. The app is not that complex or heavy graphics or such and to destroy scene when leaving is not overly taxing on the performance.
Just my opinion: consider using a game loop in the scene2 instead of all the timers. Create a Runtime ‘enterFrame’ event listener and activate it when scene shows, remove it when scene hides and/or destroys. In that loop do all the timing stuff rather then having 4 or 5 timers functioning. You would have to do some studying on how timing works in the game loop, but I feel it is going to be more efficient in the long run.
But do whichever you are comfortable with while you are still fairly new with this stuff.
There is a little code-snippet floating around the forum that you might try to find that would allow you to type just a single line of code that would stop all transitions (maybe even timers) … I just do not recall where I saw that on the forums.
Good luck.