oobarbazanoo Posted March 27, 2017 Report 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. Quote Link to comment Share on other sites More sharing options...
rhennig Posted March 27, 2017 Report 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'); Quote Link to comment Share on other sites More sharing options...
FakeWizard Posted March 27, 2017 Report 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 Quote Link to comment Share on other sites More sharing options...
rhennig Posted March 27, 2017 Report 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.