My game has multiple screens, like side-by-side rooms and I'm trying to allow user to drag between them, like presentation slides.
So I'm doing it by each room as a different scene, just for organizing the map in different files.
import Phaser from 'phaser';
import BaseScene from './../base';
export default class scene1 extends BaseScene {
parent;
constructor(handle, parent) {
super(handle);
this.parent = parent;
}
preload() {
}
create() {
this.cameras.main.setViewport(this.parent.x, this.parent.y, 200, 200);
this.add.text(10, 10, 'scene1').setOrigin(0);
}
refresh ()
{
this.cameras.main.setPosition(this.parent.x, this.parent.y);
this.scene.bringToTop();
}
}
After that, I'm adding all those scenes in the map, by loading it's class and positioning it's X side-by-side. It's working fine.
Also, the code below allows me to drag each scene at once.
async attachScene(number){
let sceneKey = 'cena' + number;
let sceneImport = await import("./../../scenes/" + number);
let sceneX = number * this.scale.width;
var win = this.add.zone(sceneX, 0, 200, 200).setInteractive().setOrigin(0);
this.input.setDraggable(win);
var c = new sceneImport.default(sceneKey, win);
win.on('drag', function (pointer, dragX, dragY) {
this.x = dragX;
c.refresh();
});
this.scene.add(sceneKey, c, true);
}
The problem is that I don't know the best way to drag all those scenes at once.
How can I do it? Maybe Camera class? Containers? Zones?