oobarbazanoo Posted March 27, 2017 Share Posted March 27, 2017 I wrote: background = me.game.add.tileSprite(0, 0, me.game.width, me.game.height, 'back'); How can I change the spritesheet shown at the back? I already have "back2" preloaded. Link to comment Share on other sites More sharing options...
rhennig Posted March 27, 2017 Share Posted March 27, 2017 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 More sharing options...
FakeWizard Posted March 27, 2017 Share Posted March 27, 2017 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 rhennig 1 Link to comment Share on other sites More sharing options...
rhennig Posted March 27, 2017 Share Posted March 27, 2017 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... Thanks for pointing! Link to comment Share on other sites More sharing options...
Recommended Posts