Jump to content

failed to load image


karanJK
 Share

Recommended Posts

i'm trying to load image on phaser 3 but on chrome consol says failed to load image also search for it, change code but can't solve it. here is my js code

 

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','src/assets/sky.png');
  
}
function create() {
    this.add.image(400, 300, 'sky');
}
function update() {
}

 

Link to comment
Share on other sites

If your file structure is like this

GameFolder {
    Assets {
        sky.png
    }
    Src {
        index.js
    }

then your load should be this

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

//if you have another folder layout its like so 
this.load.image('sky', 'assets/levels/lvl1/sky.png');

All your javascript should be inside src and all you audio video images etc inside assets

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...