I am a complete beginner to phaser. I look forward to making games using phaser.
I have tried many times but I don’t know why I can’t add image or sprite to my game. But if i add some web links then image gets added.
Please help me. And what is assets? Should image files be stored in assets?
This is my game.js code
const gameState = {
}
function preload(){
this.load.image(‘pixel’, ‘assets/pixel.png’);
this.load.image(‘background’, ‘assets/background.jpg’);
}
function create(){
this.add.image(0,0,‘background’),
gameState.circle =this.add.sprite(50,50,‘pixel’)
gameState.cursors = this.input.keyboard.createCursorKeys()
}
function update(){
if (gameState.cursors.down.isDown){
gameState.circle.y +=2;
}
if (gameState.cursors.up.isDown){
gameState.circle.y -=2;
}
if (gameState.cursors.left.isDown){
gameState.circle.x -=2;
}
if (gameState.cursors.right.isDown){
gameState.circle.x +=2;
}
}
const config ={
height:650,
width:700,
scene: {
preload,
create,
update,
}
}
const game = new Phaser.Game(config);
My folder structure is like:
my_game-- game.js, assets
assets-- background.jpg, pixel.png
I have my images saved in assets file. But it won’t work. Why?