Screen Transitioning Problem Because Of Timer

Using Storyboard, I have a menu scene, a GAME scene and a gameover scene, pretty simple…

 

The game transitions through all screens absolutely fine, until the GameOver scene. 

 

The GameOver scene has a “play again” button which is set to go back to the GAME scene.

 

The GAME scene contains a TARGET number and a separate number which rapidly increases using a timer.performWithDelay.

 

If the rapidly increasing numbers rise above the target number, the GameOver scene is called.

 

If I press “play again” in the GameOver scene, it heads back to the GAME scene but the timer is still running and in turn moves back to the GameOver scene…

 

If I do   timer.cancel(timer1)     in the same function that calls the GameOver screen when the numbers rise above the TARGET number, the “play again” button leads back to the GAME scene but the timer is paused at where it was when the GameOver scene was called.

 

I know I’m finding it difficult to explain but I literally have no idea. 

 

thanks.

Is there any specific reason for using Storyboard? Storyboard has been replaced recently by the composer API.
I’d recommend using the composer.* API instead as it’s “cleaner” to use.
 

…it heads back to the GAME scene but the timer is paused at where it was when the GameOver scene was called.

I assume you mean the display object holding the number is displaying the old number?

Your Game scene is probably still in memory when you go back to it. You have 2 options:

  1. Reset the object that displays the timer (as well as all other game specific objects/variables) before jumping to your Game Over scene. 

  2. Purge the Game scene after going to the GameOver scene so that it will re-create the scene when you go back to it

I’m pretty new to this, I heard about Storyboard and Composer but didn’t know which one to use so I just went for Storyboard… sods law I guess! 

but thankyou for your help I really appreciate it, I’ll have a look at the composer API and ill consider migrating my code to composer API rather than Storyboard

thankyou!!

Is there any specific reason for using Storyboard? Storyboard has been replaced recently by the composer API.
I’d recommend using the composer.* API instead as it’s “cleaner” to use.
 

…it heads back to the GAME scene but the timer is paused at where it was when the GameOver scene was called.

I assume you mean the display object holding the number is displaying the old number?

Your Game scene is probably still in memory when you go back to it. You have 2 options:

  1. Reset the object that displays the timer (as well as all other game specific objects/variables) before jumping to your Game Over scene. 

  2. Purge the Game scene after going to the GameOver scene so that it will re-create the scene when you go back to it

I’m pretty new to this, I heard about Storyboard and Composer but didn’t know which one to use so I just went for Storyboard… sods law I guess! 

but thankyou for your help I really appreciate it, I’ll have a look at the composer API and ill consider migrating my code to composer API rather than Storyboard

thankyou!!