我无法使用 Phaser 3 中的创建功能将任何内容加载到 canvas

I cannot get anything to load onto the canvas with the create function in Phaser 3

我无法预加载图像

我试过将它转换为 url,我试过将其复制到项目文件夹中的文件,我试过只输入文件名。

function preload(){
  this.load.image('sky', 'assets/sky.png');
  this.load.image('ground', 'assets/platform.png');
  this.load.spritesheet('dude', 'assets/dude.png');
  this.load.image('star', 'assets/star.png');
} // preloads all of the files I will need to make the game
function create() {
  this.add.sprite(200, 200, 'star');
} // applies the files 
function update() {

}// update every frame




var config = {
  type: Phaser.AUTO,
  width: 800,
  height: 600,
  backgroundColor: '#FF0000',
  physics: {
    default: 'arcade',
    arcade: {
      gravity: {y:200},
      debug: false
    }
  },
scene: {
  preload,
  create,
  update
},

} // configures the game 

var game = new Phaser.Game(config);

我想在 canvas 上成功显示图像,但它只显示一个黑框,上面有一些绿线。非常感谢任何有关如何解决此问题或我遗漏的提示,谢谢。

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre><code>    function preload() {
      this.load.image('sky', 'file:///home/chronos/u-fc7808c01e889e74148d1013b69f0a2241def976/Downloads/testprogram-atom.js/assets/sky.png');
      this.load.image('ground', 'assets/platform.png');
      this.load.spritesheet('dude', 'assets/dude.png');
      this.load.image('star', '/home/jojobinks/Desktop/testprogram-atom.js/star.png');
    }
    function create() {
      this.add.image(0, 0, 'sky');
    }
    function update() {

    }




    var config = {
      type: Phaser.AUTO,
      width: 800,
      height: 600,
      backgroundColor: '#FF0000',
      physics: {
        default: 'arcade',
        arcade: {
          gravity: {y:200},
          debug: false
        }
      },
    scene: {
      preload,
      create,
      update
    },

    }

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

打开浏览器开发工具并查看网络请求。它实际上是在加载文件吗?还是那里有 404 错误?此外,您不能从 file:// 加载,您的游戏必须 运行 来自网络服务器。如果您只是在浏览器中打开 index.html,它将无法运行。请按照 Phaser 网站上的入门指南了解更多详细信息。