phaser 3: Uncaught TypeError: this.game.scene.launch is not a function unable to launch i have implemented a scene manager and im having trouble.
please help i really want to be able to use this scenemanager as it makes stuff a lot easier. i need to use launch because i am having a battle with a lot of temporary variables like the health bars and stuff and when i open the inventory to use an item i need to be able to resume the battle. it lets me use start, and pause, and resume, but when i start it stops the previous scene. i need to use launch to get around this im pretty sure. but its not letting me. .
the line im having trouble with is this line
this.game.scene.launch(newSceneName, data);
the error im getting is:
Uncaught TypeError: this.game.scene.launch is not a function
i tried to provide context of this.game.scene. i never used it like this before. something wrong with the way im using it.
//when i start my game i run this.
const game = new Phaser.Game(config);
globals.initSceneManager(game);
game.scene.start('MainMenuScene');
//in my globals class i have this:
class Globals {
constructor() {
this._inputManager = new InputManager();
this._sceneManager = null;
}
initSceneManager(game) {
this.sceneManager = new SceneManager(game, this.inputManager); // Pass the input manager
this.sceneManager.init(); // Initialize the SceneManager
}
//and getters and setters.
//this is my scenemanager.
class SceneManager {
constructor(game, inputManager) {
this.game = game;
this.inputManager = inputManager;
this.currentScene = null;
// this.sceneManager = game.scene;
}
init() {
this.inputManager.init(this.game); // Initialize input manager with the game context
}
transitionTo(newSceneName, data = {}, pauseCurrent = false) {
console.log(`Transitioning from ${this.currentScene} to ${newSceneName}`);
console.log('SceneManager methods:', Object.keys(this.game.scene));
console.log('Is start a function?', typeof this.game.scene.start === 'function');
console.log('Is launch a function?', typeof this.game.scene.launch === 'function');
// console.log('SceneManager methods:', Object.keys(this.sceneManager));
// Disable input listeners immediately
this.inputManager.disableListeners();
try{
if (this.currentScene) {
if (pauseCurrent) {
// this.game.scene.pause(this.currentScene);
// console.log('Pausing: ', this.currentScene);
console.log('not stopping');
} else {
this.game.scene.stop(this.currentScene);
console.log('Stopping: ', this.currentScene);
}
}
// Set a short delay before starting the new scene
setTimeout(() => {
// this.currentScene = newSceneName;
// this.game.scene.start(newSceneName, data);
this.currentScene = newSceneName;
if (pauseCurrent) {
console.log('Launching new scene:', newSceneName);
this.game.scene.launch(newSceneName, data);
} else {
console.log('Starting new scene:', newSceneName);
this.game.scene.start(newSceneName, data);
}
// Set up new input listeners with a delay
setTimeout(() => {
const inputs = this.getSceneInputs(newSceneName);
console.log('Setting inputs for', newSceneName, ':', inputs);
this.inputManager.setSceneInputs(newSceneName, inputs); }, 50);
}, 25);
} catch (error) {
console.error('Error during scene transition:', error);
}
}