Reputation: 35
I'm having a problem changing scenes when I reach the area that should trigger the second level in the game I'm developing. For some reasons instead of showing the second level the game shows a black screen and no errors on the console. I think that the answer to my question is here (http://www.html5gamedevs.com/topic/37617-trouble-changing-scenes-in-phaser-3/) as the guy who asked the question had my problem and managed to resolve it, but I don't understand his last post.
the way I call the second scene in my first scene is the function:
PassaggioLivello() {
if(this.player.sprite.x > 15400){
this.scene.start(MainScene2);
}
}
And both scenes are included in the config file:
import {MainScene} from "./main-scene.js";
import {MainScene2} from "./main-scene.js";
let config = {
type: Phaser.AUTO,
width: 1280,
height: 720,
backgroundColor: "#000c1f",
parent: "game-container",
scene: [MainScene, MainScene2],
pixelArt: true,
physics: { default: "matter" },
plugins: {
scene: [
{
plugin: PhaserMatterCollisionPlugin, // The plugin class
key: "matterCollision", // Where to store in Scene.Systems, e.g.
scene.sys.matterCollision
mapping: "matterCollision" // Where to store in the Scene, e.g. scene.matterCollision
}
]
}
};
let game = new Phaser.Game(config);
Can you please help me? I don't understand my error.
Upvotes: 2
Views: 1869
Reputation: 1122
The this.scene.start()
method requires the identifying key of the scene you want to start--not the scene object itself.
Each scene being imported should have a key declared in the constructor method, like this:
constructor() {
super({ key: 'game' });
}
Then, you should be able to start the scene you want by calling this.scene.start('game');
Upvotes: 3