更改场景 Phaser 3 时出现黑屏
Black screen when changing scene Phaser 3
当我到达应该触发我正在开发的游戏中的第二关的区域时,我在更改场景时遇到了问题。由于某些原因,游戏没有显示第二关,而是显示黑屏并且控制台上没有错误。我认为我的问题的答案就在这里 (http://www.html5gamedevs.com/topic/37617-trouble-changing-scenes-in-phaser-3/),因为问这个问题的人遇到了我的问题并设法解决了它,但我不明白他最后 post.
我在第一个场景中调用第二个场景的方式是函数:
PassaggioLivello() {
if(this.player.sprite.x > 15400){
this.scene.start(MainScene2);
}
}
并且两个场景都包含在配置文件中:
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);
你能帮帮我吗?我不明白我的错误。
this.scene.start()
方法需要您要启动的场景的标识键——而不是场景对象本身。
导入的每个场景都应该在构造方法中声明一个键,如下所示:
constructor() {
super({ key: 'game' });
}
然后,您应该可以通过调用this.scene.start('game');
来启动您想要的场景
当我到达应该触发我正在开发的游戏中的第二关的区域时,我在更改场景时遇到了问题。由于某些原因,游戏没有显示第二关,而是显示黑屏并且控制台上没有错误。我认为我的问题的答案就在这里 (http://www.html5gamedevs.com/topic/37617-trouble-changing-scenes-in-phaser-3/),因为问这个问题的人遇到了我的问题并设法解决了它,但我不明白他最后 post.
我在第一个场景中调用第二个场景的方式是函数:
PassaggioLivello() {
if(this.player.sprite.x > 15400){
this.scene.start(MainScene2);
}
}
并且两个场景都包含在配置文件中:
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);
你能帮帮我吗?我不明白我的错误。
this.scene.start()
方法需要您要启动的场景的标识键——而不是场景对象本身。
导入的每个场景都应该在构造方法中声明一个键,如下所示:
constructor() {
super({ key: 'game' });
}
然后,您应该可以通过调用this.scene.start('game');