Popup Scene

I am working with multiple scenes, where there is a mini-game within a game. I’m trying to get the code from the multi-scene demo to work, using some of that code to launch my own single scene as a popup window, but I’m finding it hard to parse. It would be really useful if the examples were commented!!

So I think my problem is the createWindow function:

createWindow (func)
{
    var x = Phaser.Math.Between(400, 600);
    var y = Phaser.Math.Between(64, 128);

    var handle = 'window' + this.count++;

    var win = this.add.zone(x, y, func.WIDTH, func.HEIGHT).setInteractive().setOrigin(0);

    var demo = new func(handle, win);

    this.input.setDraggable(win);

    win.on('drag', function (pointer, dragX, dragY) {
        this.x = dragX;
        this.y = dragY;
        demo.refresh()
    });
    this.scene.add(handle, demo, true);
}

My questions are: What is “count”? Why are we counting the window? What is “demo”? And what is the third parameter for in “this.scene.add(handle, demo, true)”?

Simplified, that is

var count = 0;

function createScene (SceneClass) {
  var sceneKey = 'window' + count++;
  var scene = new SceneClass(sceneKey);

  this.scene.add(sceneKey, scene, true);
}

The counting is just to give each scene a unique key. The third param starts the scene once it’s added.

That example is a little unusual, though. For a mini-game you could do

// In 'game'
this.scene.pause().launch('mini');

// In 'mini'
this.scene.stop().resume('game');
1 Like

Thank you. I’ll try that out.