Search the Community
Showing results for tags 'preload.js'.
-
Hello All, I am completely new to Phaser. For learning purposes, I did a little game from a recent book that I bought, and put it on my website, that I use for testing my stuff. Here is the URL: http://www.retroinvaders.net/shump/build/index.html The issue is that the game assets won't load properly at first time, it's only when I refresh the page, at least 4 times, that I see all the assets of the game properly loaded. The Web Console (Firefox) says: Phaser.Cache.getImage: Key "enemyBullet" not found in Cache. Same error for all the game assets is repeated again and again, so not just "enemyBullet", but all the assets. Here is the code of the Preload.js file. export default class Preload { constructor() { this.asset = null; this.ready = false; } preload() { this.load.image('loading_bg', '../assets/images/loading_bg.jpg'); } create() { //background for game this.add.sprite(0,0, "loading_bg"); this.asset = this.add.sprite(this.game.width/2,this.game.height/2, 'preloader'); this.asset.anchor.setTo(0.5, 0.5); this.load.onLoadComplete.addOnce(this.onLoadComplete, this); this.load.setPreloadSprite(this.asset); //do all your loading here //this.load.image('player', '../assets/images/player.png'); //width and height of sprite this.load.image('bg', '../assets/images/bg.jpg'); this.load.image('bullet', '../assets/images/bullet.png'); this.load.image('enemy', '../assets/images/enemy.png'); this.load.image('explosion', '../assets/images/explosion.png'); this.load.spritesheet('player', '../assets/images/gunbot.png', 214, 269); //width and height of sprite this.load.image('hexagon', '../assets/images/hexagon_particle.png'); //this.load.image('bullet', '../assets/images/bullet.png'); this.load.image('enemyBullet', '../assets/images/enemyBullet.png'); //this.load.image('bg', '../assets/images/bg.jpg'); this.load.image('health_bar', '../assets/images/health_bar.png'); this.load.image('health_holder', '../assets/images/health_holder.png'); this.load.image('circle', '../assets/images/circle.png'); //staaaart load this.load.start(); } update() { if(this.ready) { this.game.state.start('game'); } } onLoadComplete() { this.ready = true; } } What am I doing wrong? Aany help, would be greatly appreciated. Thank you.