RyuMaster Posted June 20, 2014 Share Posted June 20, 2014 Hi! I have place holder sprite with empty avatar image, and I want to swap it with real avatar after user uploads it; Place holder image has 'avatar_large' id and is loaded during boot time; that.cache.removeImage('avatar_large');that.load.image('avatar_large', 'assets/proper_avatar.png');that.avatarLarge.loadTexture('avatar_large'); This code actually clears the texture from cache, and also removes place holder image, but never shows proper one. What else am I missing? Link to comment Share on other sites More sharing options...
lewster32 Posted June 20, 2014 Share Posted June 20, 2014 Untested, but something like this maybe?// the last parameter tells it to overwrite the existing key, no need to use removeImagethat.load.image('avatar_large', 'assets/proper_avatar.png', true);// use the onLoadComplete event to ensure you update the image after it has loadedthat.load.onLoadComplete.addOnce(function() { that.avatarLarge.loadTexture('avatar_large');}); Link to comment Share on other sites More sharing options...
RyuMaster Posted June 20, 2014 Author Share Posted June 20, 2014 Thank you a lot, will try this out! Link to comment Share on other sites More sharing options...
RyuMaster Posted June 21, 2014 Author Share Posted June 21, 2014 This is odd, but I can't get it working with any combination. After event complete, sprite is not changing. loadTexture works with pre-defined sprites I have on general Preload.js, but if I load later in the game, all I got from loadTexture is empty green square. Link to comment Share on other sites More sharing options...
lewster32 Posted June 21, 2014 Share Posted June 21, 2014 Very odd. What happens if you create a new sprite with the key after loading the new avatar image? We should probably narrow it down and work out if there's a problem with loadTexture or if the issue lies somewhere in loading the avatar. Link to comment Share on other sites More sharing options...
RyuMaster Posted June 22, 2014 Author Share Posted June 22, 2014 Hmmm, seems like image loading problem, this code doesn't work: var loaderGame1 = new Phaser.Loader(game);loaderGame1.image = ('avatar_large2', 'uploads/ryumaster.png', true); loaderGame1.onLoadComplete.addOnce(function() { //that.avatarLarge.loadTexture('avatar_large'); that.confirmPasswordBox = that.add.sprite(0, 0, 'avatar_large2'); }); Though, image will get displayed ,it I load it normally via Boot-Preloader routine; Link to comment Share on other sites More sharing options...
Recommended Posts