Having a hard time changing background image

Hi people, I started learning Phaser couple a days ago, I have rendered my game but I can’t set my background to the desired photo, the console doesn’t give me any errors and I can’t figure out what I am doing wrong? Here is my code:

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

var game = new Phaser.Game(config);

function preload() {
this.load.image(‘background’, ‘./assets/star-background.jpg’);
}

function create() {
this.add.image(400, 300, ‘background’);
}

function update() {

}

Hello @philip9,

please see the examples here: https://labs.phaser.io/edit.html?src=src/game%20objects/images/single%20image.js

This one is a single image with rotation but you can find lots of them in labs.phaser.io

Please try to copy this:

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

var game = new Phaser.Game(config);

function preload() {
    this.load.image('background', './assets/star-background.jpg');
}

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

function update() {

}

Only difference that you are using different kind of quetos use double or single quetos instead and it should work :slight_smile:

1 Like

Wow, so the problem was that my quotes were a different ASCI character? No wonder that was driving me nuts after checking so much examples, thanks!

1 Like