Composor

I read some of the other responses above…  so the initial issue ‘car’ stays visible on screen and game does not stop; the car according to the responses above is no longer the issue, just the ‘game doesn’t stop’ is apparently the remaining issue. Is that correct?

Can you post a more detailed explanation of ‘game doesn’t stop’  or  ‘the game still carry on when i move out of the screen’?  Do you mean there are some images (other then the car), such as background or some other images that are still on the screen?

ok, the game is a racing game. When i move to the screen, the game started to run and play. While, when i move out of the screen (changing to menu screen or others ), the game suppose to stop and the game will reload if i move back to the game. Yet, the game still continue to run even i move to other screen and the game doesn’t reload when i move back to screen. 

The game is ok when i just using the original code but when move to composer it have  this kind of problem.

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.

  1. 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”)

  1. 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

  1. 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.