Sign in to follow this  
oobarbazanoo

Replace background tileSprite.

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');

 

Share this post


Link to post
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

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.