The second problem of phaser game

接着上篇往下

1、相机跟随人物及设置相机边界问题

1
2
3
this.cameras.main.startFollow(this.player);//相机跟随
this.cameras.main.setBounds(0, 0, map.displayWidth, map.displayHeight);

2、场景转换

具体实现如下
1
2
3
playBtn.setInteractive();
playBtn.on('pointerdown', () => this.scene.start('gamePlay'))

值得注意的是,在配置文件中需要在场景里加入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const config = {
type: Phaser.AUTO,
parent: 'game',
width: 500,
heigth: 500,
scale: {
mode: Phaser.Scale.RESIZE,
autoCenter: Phaser.Scale.CENTER_BOTH
},

physics: {
default: 'arcade',
arcade: {
gravity: { y: 500 },
debug: true,
},
},
scene: [
gameStart,
gamePlay,
]
};
const game = new Phaser.Game(config);

源代码过段时间放GitHub