Jump to content

"Preparing" a scene before it shuts down


GreenCloversGuy
 Share

Recommended Posts

Hello all, 

I have a scene in my game, a menu UI scene, which I want to "Dismantle" before it shuts down. Basically, I want the text boxes to fade away and the character art to move out of the screen. I've used tweens to have the items enter the scene when the scene is created, and I've set up the tweens so that they will yo-yo and I've paused them just before they start to yo-yo, so all I need to to is resume the tweens on my gameobjects. 

My issue is that I need to set up my game so that when a scene should stopped, it instead resumes these tweens, waits for them to finish and then stop the scene. I'm aware that I could do by having any code that closes the scene first emit a "stopscene" event, have my gameobjects listen for this event, resume the tween and then emit an event after they have both finished, however this seems messy and complicated. I've looked into transitions but I don't believe you can use transitions on scenes that have paused or launched and when I tried playing with them earlier, I found myself resetting the scene I was trying to resume. 

Is there a nice easy way for me to "prepare" a scene for stopping, perhaps through the scene manager or by extending the scene and overriding the code that will stop the scene?

Link to comment
Share on other sites

I still think transitions would work perfectly for this, but if you don't want to use them that's fine. However, you're going to need to handle this with your own code, because there's nothing built into the Scene Manager for it (other than transitions!) because, if you think about it, while those objects are tweening out, etc the Scene hasn't shutdown at all, it's still perfectly active and you want it to remain as such until those transitions (hint hint) are completed.

Link to comment
Share on other sites

Having come back to it after a day, I can see that a transition will do most of what I want. I was treating them more like tweens then as, for lack of a better word, handlers. I still have an issue with being unable to work with paused and resumed scenes, having to force them to sleep instead which isn't perfect. Is it possible to run a transition and have it pause the scene instead? Possibly by having a go-between scene which is launched and which instantly transitions to the scene I want to see? 

 

 

Link to comment
Share on other sites

Yes, you can use the Transition Configuration object to tell the Scene to sleep instead of stop:

    /**
     * @typedef {object} Phaser.Scenes.ScenePlugin.SceneTransitionConfig
     * 
     * @property {string} target - The Scene key to transition to.
     * @property {integer} [duration=1000] - The duration, in ms, for the transition to last.
     * @property {boolean} [sleep=false] - Will the Scene responsible for the transition be sent to sleep on completion (`true`), or stopped? (`false`)
     * @property {boolean} [allowInput=false] - Will the Scenes Input system be able to process events while it is transitioning in or out?
     * @property {boolean} [moveAbove] - Move the target Scene to be above this one before the transition starts.
     * @property {boolean} [moveBelow] - Move the target Scene to be below this one before the transition starts.
     * @property {function} [onUpdate] - This callback is invoked every frame for the duration of the transition.
     * @property {any} [onUpdateScope] - The context in which the callback is invoked.
     * @property {any} [data] - An object containing any data you wish to be passed to the target Scenes init / create methods.
     */

 

Link to comment
Share on other sites

Thanks for the update, however sleep is not the same as pause. I wanted the player to still see the main game when opening the menu, sleeping the scene stops it from rendering. Also when I transition back to the main scene, if I've paused the scene I'm transitioning to, the scene does not resume, it restarts. Not perfect!

I managed to create the effect I wanted by creating two additional scenes. 

class WorldToDiaScene extends Phaser.Scene{
  constructor(){
    super('WorldToDiaScene')
  }
  create(){
    this.scene.transition({
        target: 'DiaScene',
        duration: 1000,
    })
  }
}

class DiaToWorldScene extends Phaser.Scene{
  constructor(){
    super('DiaToWorldScene')
  }
  create(){
    this.events.on('transitioncomplete', ()=>{
      this.scene.stop('DiaToWorldScene');
    })
    this.scene.resume('WorldScene');
  }
}

I launch the first scene from my main scene, which transitions into the menu. Then, when my menu is closed, I have it transition to the second scene, which resumes my main scene and, after the transition is completed, stops itself. 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...