Phaser 3 抛出 "Texture.frame missing:" 警告并且无法加载框架,我该如何解决?

phaser 3 throws "Texture.frame missing:" warning and fails to load frame, how do I fix it?

注意:我的代码已经运行并渲染精灵

只需点击一下即可play with


我在学习a phaser3 loader example

这是我写的代码

class BootScene extends Phaser.Scene {
  constructor() {
    super();
  }
  preload() {
    this.load.path = 'https://raw.githubusercontent.com/liyi93319/phaser3_rpg/main/part1/assets/';
    this.load.atlas('player', 'knight_atlas.png', 'knight_atlas.json');
  }
  create() {
    var player = this.add.sprite(80, 100, 'player', 0);
    player.setScale(.5);
  }
}

var config = {
  width: 400,
  height: 300,
  pixelArt: true,
  physics: {
    default: 'arcade',
    arcade: {
      gravity: { y: 0 },
    }
  },
  backgroundColor: 0x000000,
  scene: [BootScene]
}

var game = new Phaser.Game(config);
<script src="https://cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.js"></script>

到目前为止一切正常。

但是,将 create() 更改如下

  create() {
    var player = this.add.sprite(80, 100, 'player', 5);
    player.setScale(.5);
  }

未按预期加载框架并引发警告

Texture.frame missing: 5

我比较了'knight_atlas.json'文件和官方例子中的the one。我看不出区别。

我也检查了 doc 但没有找到解决方案。

我错过了什么?

如果你想使用第三个参数,你必须使用字符串(或纹理对象),在这种情况下,图集中的 filename 应该可以工作。这是 relevant documentation

class BootScene extends Phaser.Scene {
  constructor() {
    super();
  }
  preload() {
    this.load.path = 'https://raw.githubusercontent.com/liyi93319/phaser3_rpg/main/part1/assets/';
    this.load.atlas('player', 'knight_atlas.png', 'knight_atlas.json');
  }
  create() {
    var player = this.add.sprite(80, 100, 'player', 'Attack (3).png');
    player.setScale(.5);
    
    var player2 = this.add.sprite(240, 100, 'player', 'Idle10');
    player2.setScale(.5);
  }
}

var config = {
  width: 400,
  height: 300,
  pixelArt: true,
  physics: {
    default: 'arcade',
    arcade: {
      gravity: { y: 0 },
    }
  },
  backgroundColor: 0x000000,
  scene: [BootScene]
}

var game = new Phaser.Game(config);
<script src="https://cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.js"></script>