MrLane Posted February 23, 2019 Share Posted February 23, 2019 var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create}); function preload(){ game.load.image('tardis', "./tardis.jpg"); } function create() { game.stage.backgroundColor = '#182d3b'; var sprite1 = game.add.sprite(40, 100, 'tardis'); //if i move it to preload t works fine game.load.image('flower', './flower.jpeg'); game.load.start(); var sprite2 = game.add.sprite(100, 100, 'flower'); //ERROR: //Phaser.Cache.getImage: Key "flower" not found in Cache } Link to comment Share on other sites More sharing options...
gyfak Posted April 9, 2019 Share Posted April 9, 2019 You must load flower pic on preload function Link to comment Share on other sites More sharing options...
charlie_says Posted April 16, 2019 Share Posted April 16, 2019 sure @MrLane the problem is you're trying to add the new image before it's loaded. so: game.load.image('flower', './flower.jpeg'); game.load.onLoadComplete.add(newImageLoaded, this); game.load.start(); function newImageLoaded() { var sprite2 = game.add.sprite(100, 100, 'flower'); } Link to comment Share on other sites More sharing options...
Recommended Posts