Caikozolyv Posted March 28, 2017 Report Share Posted March 28, 2017 Hello everybody, I'm new in javascript and doing a phaser tutorial to make a virtual pet game. I cut my code into different files (Boot, Preload, Menu and Game) but I got this error : " phaser.js:71363Phaser.Cache.getImage: Key "background" not found in Cache. " I think that my GameState.js is loaded before my PreloadState.js ... Here is my code : var PreloadState = { preload: function () { this.logo = this.add.sprite(this.game.world.centerX, this.game.world.centerY, 'logo'); this.logo.anchor.setTo(0.5); this.preloadBar = this.add.sprite(this.game.world.centerX, this.game.world.centerY + 128, 'preloadBar'); this.preloadBar.anchor.setTo(0.5); this.load.setPreloadSprite(this.preloadBar); this.load.image('background', 'resources/img/background.svg', 800, 600); this.load.image('apple', 'resources/img/apple2.png'); this.load.image('candy', 'resources/img/candy2.png'); this.load.image('rotate', 'resources/img/rotate2.png'); this.load.image('toy', 'resources/img/toy2.png'); this.load.spritesheet('girl', 'resources/img/PlayerSprite0.png', 65, 70, 1, 1); }, create: function () { this.state.start('GameState'); }, }; Thank you for answering me Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.