简体   繁体   中英

Phaser3 javascript failed to load image

i am trying to load assets on javascript using phaser3 engine but on chrome consol it says 'failed to load image' here is my HTML & Javascript code look where i made mistake:

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>PhaserGame</title>
    <script = "text/javascript" src = "phaser.js"></script>
  </head>
  <body>
    <script src="script.js"></script>

  </body>
</html>

JAVASCRIPT:

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

var game = new Phaser.Game(config);


function preload() {
    this.load.image('sky','assets/sky.png');

}

function create() {
    this.add.image(400, 300, 'sky');
}

function update() {

}

I think there is some problem with your image location the same code worked for me, with only changing the image URL

https://codepen.io/devsumanmdn/pen/zaeZwJ?editors=0010

在项目中创建文件夹“public”并将图像放在这里

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM