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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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