noelrb Posted April 30, 2014 Share Posted April 30, 2014 Hi everyone. I am creating a game that consuming an image api. Is it possible to load or change an image outside the preload method? For example, in the create method. I am making a game with a lot of images, and i need to load in game runtime. I tryed to change de cache object, but without hit. Also tryed to use game.load.image, but not run out of preLoad method. Any idea? Thanks! Link to comment Share on other sites More sharing options...
george Posted May 4, 2014 Share Posted May 4, 2014 Ho noelrb,you can create your own instance of the loader class to do this. The loader will put everything in the cache so it's ready to use.But beware of overriding existing ids. This won't magically update existing objects using that texture. Only the ones created afterwards.To update existing elements:You have to refresh them with sprite.loadTexture. To update an entire texture atlas you have to refresh every single element with loadTexture that uses a texture from the atlas.loader = new Phaser.Loader(game)loader.image('someimage', '//url/to/image' )loader.atlasJSONHash('anotherAtlas', '//url/to/texture' , '//url/to/atlas' )loader.onLoadComplete.addOnce(onLoaded)loader.start()onLoaded = function(){ console.log('everything is loaded and ready to be used')}Regards George Fenopiù, Lypzis, VitaZheltyakov and 2 others 5 Link to comment Share on other sites More sharing options...
ForgeableSum Posted May 16, 2015 Share Posted May 16, 2015 Ho noelrb,you can create your own instance of the loader class to do this. The loader will put everything in the cache so it's ready to use.But beware of overriding existing ids. This won't magically update existing objects using that texture. Only the ones created afterwards.To update existing elements:You have to refresh them with sprite.loadTexture. To update an entire texture atlas you have to refresh every single element with loadTexture that uses a texture from the atlas.loader = new Phaser.Loader(game)loader.image('someimage', '//url/to/image' )loader.atlasJSONHash('anotherAtlas', '//url/to/texture' , '//url/to/atlas' )loader.onLoadComplete.addOnce(onLoaded)loader.start()onLoaded = function(){ console.log('everything is loaded and ready to be used')}Regards GeorgeWell that just saved me about 2 hours of troubleshooting. Thanks! Link to comment Share on other sites More sharing options...
ForgeableSum Posted May 16, 2015 Share Posted May 16, 2015 Spoke to soon. I noticed that after creating a new instance of the load class and loading a bunch of images after preload, many of my existing textures no longer load. I get errors like: Texture with key 'cursor' not found.phaser-2.3.0.js:35781 Texture with key 'brush' not found.phaser-2.3.0.js:35781 Texture with key 'brush2b' not found. I realize this probably has something to do with what George mentioned, "overriding existing ids." What IDs could I be overwriting if the texture keys are unique? Link to comment Share on other sites More sharing options...
staff0rd Posted March 14, 2016 Share Posted March 14, 2016 @feudalwars did you solve this? I was getting something similar as I was trying to instantiate a separate loader and have two different loading threads. It was because Phaser.Loader will make calls to shared game objects like StateManager meaning there's not any point in instantiating a separate one. Link to comment Share on other sites More sharing options...
Recommended Posts