Jump to content

scene.init.call is not a function (3.11-3.15)


RetroGameDev
 Share

Recommended Posts

Hi,

I have ran into an issue when starting scenes for a second time. I have three scenes, a main menu scene, a level scene and the gameover scene. When I go from the level scene to any other scene and try go back to the level scene
I get the error: Uncaught TypeError: scene.init.call is not a function.

I have noticed that if I go back into the main menu scene or game over scene there is no problem, only on the level scene. What I noticed was thats the only scene I use the import modules for example:

import Init from "../init.js";
import Player from "../player.js";
import Controls from "../modules/controls.js";
 
/**
* Create arcade mode
*/
export default class levelScene extends Phaser.Scene {
constructor() {
super({ key: 'levelScene' });
}
 
preload() {
 
}
 
create() {
this.init = new Init(this);
//etc
}
 
update() {
 
}
 
}

I tried importing the Init module inside the game over scene and had the same error if I used this.scene.restart(); and when I took it back out the scene restarted no problems.

I have been using the file structure and module approach from https://itnext.io/modular-game-worlds-in-phaser-3-tilemaps-2-dynamic-platformer-3d68e73d494a tutorial

I am still quite new with using modules so I could be something trivial but any help or work around will be great as at the moment I need to reload the page each time. Any other info needed, please let me know.
(I have tried using versions 3.11 to 3.15 and had the same error)

 

edit: more info added. 

Thanks,

Link to comment
Share on other sites

Hi Samme,

Thank you! I renamed this.init to this.setup and made the same changes where necessary and the level scene loaded.
I had been scratching my head at this for a while and would of never thought it was because of (this.init).

Thanks again really appreciate it :)   

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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