How to properly handle the applicationSuspend event when using Storyboard or Composer.

I have a problem with properly handling “suspend” events when using Storyboard. When the application has been suspended, I want to tell Storyboard to go to my pause screen. But it seems that storyboard.gotoScene during the applicationSuspend event is ignored.

So, I’m doing gotoScene in the applicationResume event, and that works. The problem with this though, is that Storyboard first activates my previous scene for half a second when the app resumes, then goes to my pause screen. This looks really bad, because my previous screen usually plays sounds and starts animations, so it looks buggy. The previous screen should not show up at all when the user is resuming the game.

Here’s what I’m doing:

local function onSystemEvent(event)     if (event.type == "applicationExit") then         game.save()         stage.stopAll()     elseif event.type == "applicationSuspend" then         game.save()         storyboard.purgeAll()         storyboard.gotoScene("pause")     elseif event.type == "applicationResume" then         storyboard.purgeAll() storyboard.gotoScene("pause")     end end

Is there any way I can manually tell Storyboard what scene should be resumed? Or maybe have it purge the active scene in the Suspend event? There must be a way to do this.

Any ideas?

Thanks,

George

When you suspend you probably don’t have time to purge scenes and you certainly won’t have time to goto a scene and have it get created.  

Any thing you want “Paused” when the app resumes, you will need to pause during the suspend.  This includes timers, transitions, physics, etc.  You can goto your paused scene on resume.

Rob

Thanks for the reply, Rob, but I might not have been very clear. My problem is that when I go to my pause screen on resume, Storyboard still resumes my previous scene for half a second or so, and THEN goes to my pause screen. I would like Storyboard to resume directly to my pause scene and not show my previous scene at all. Is this possible?

If your pause screen was already created (perhaps using computer.loadScene() or something like that) but not showing, you might have time to get to it before the app suspends, but you would not want to do that remove all call.

Rob

A simple fix might be to load a black(any color) blank “splash” any make isVisible = false then on suspend a simple call isVisible = true will result in a blank screen.

Then when resume get blank screen then pause.

T.

Rob, I’ve tried going to an empty blank scene in the applicationSuspend event, but it doesn’t go to it. I suspect that Storyboard receives the suspend event before I get it, and is disabling any calls to gotoScene.

TokeKnee, that’s a good idea, and that would solve the issue with seeing the last scene, but sounds from that scene will still be incorrectly played for a second.

When you suspend you probably don’t have time to purge scenes and you certainly won’t have time to goto a scene and have it get created.  

Any thing you want “Paused” when the app resumes, you will need to pause during the suspend.  This includes timers, transitions, physics, etc.  You can goto your paused scene on resume.

Rob

Thanks for the reply, Rob, but I might not have been very clear. My problem is that when I go to my pause screen on resume, Storyboard still resumes my previous scene for half a second or so, and THEN goes to my pause screen. I would like Storyboard to resume directly to my pause scene and not show my previous scene at all. Is this possible?

If your pause screen was already created (perhaps using computer.loadScene() or something like that) but not showing, you might have time to get to it before the app suspends, but you would not want to do that remove all call.

Rob

A simple fix might be to load a black(any color) blank “splash” any make isVisible = false then on suspend a simple call isVisible = true will result in a blank screen.

Then when resume get blank screen then pause.

T.

Rob, I’ve tried going to an empty blank scene in the applicationSuspend event, but it doesn’t go to it. I suspect that Storyboard receives the suspend event before I get it, and is disabling any calls to gotoScene.

TokeKnee, that’s a good idea, and that would solve the issue with seeing the last scene, but sounds from that scene will still be incorrectly played for a second.