代码素材后续提供下载链接
import Phaser from 'phaser'
class GameScene extends Phaser.Scene {
constructor() {
super('GameScene')
this.score = 0
this.lives = 6
}
preload() {
this.load.image('bg', 'assets/example/scene/sky4.png')
this.load.image('crate', 'assets/example/scene/crate.png')
}
create() {
// Store the score and lives in the Game Registry
// 把数据存到Game Registry里
this.registry.set('score', this.score)
this.registry.set('lives', this.lives)
// 添加背景图片
this.add.image(400, 300, 'bg')
// 添加箱子
for (let i = 0; i < 64; i++) {
let x = Phaser.Math.