Jump to content

Replace background tileSprite.


oobarbazanoo
 Share

Recommended Posts

No sure if this is the best aproach but you can do something like (on create):

        this.bk = this.add.tileSprite(0,0,this.game.world.width,this.game.world.height,'bkg2');

And on update:

if(condition to change background)
     this.bk.loadTexture('bkg');

 

Link to comment
Share on other sites

the this.bk variable gets overwritten  by the second line ,so why defining it twice anyway? He only needs to make sure it's loaded and then store the tileSprite to a variable (background) and just call background.loadTexture( "back2" ) whenever he needs the base texture to be replaced.  

Also note that the old texture is removed , so in order to apply the previous texture you may need to repeat the same process again.

For more information refer to the API docu

Link to comment
Share on other sites

52 minutes ago, FakeWizard said:

the this.bk variable gets overwritten  by the second line ,so why defining it twice anyway? He only needs to make sure it's loaded and then store the tileSprite to a variable (background) and just call background.loadTexture( "back2" ) whenever he needs the base texture to be replaced.  

Also note that the old texture is removed , so in order to apply the previous texture you may need to repeat the same process again.

For more information refer to the API docu

Yep, my bad. I've edited to avoid confusion but declaring it 2 times was really nonsense... :P Thanks for pointing!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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