KaranJK
KaranJK

Reputation: 23

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() {

}

Upvotes: 1

Views: 1364

Answers (2)

create folder "public" in project and put images here

Upvotes: 0

Suman Kundu
Suman Kundu

Reputation: 1742

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

Upvotes: 1

Related Questions