Jump to content

Change loaded texture


RyuMaster
 Share

Recommended Posts

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

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

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...