psyked Posted May 10, 2015 Share Posted May 10, 2015 hi,In my project, i'm trying to change the background of a game but i've got some issues.I use a tileSprite as background, i had it in the beginning of create() so it's behind the layers and other objects :(where my loaded images are named bg0, bg1, ...)background = game.add.tileSprite(0, 0, 800, 600, 'bg' + layers.fond);but i want to change it by pressing a key and there it goes wrong :if i use again rhis code with a different image, it creates a new tileSprite IN FRONT of the previous objects i've created.So i tried to change the tileSprite by using :background.key = 'bg' + layers.fond;But then, nothing change, the new image linked with background is good but i can't "refresh" the displayed sprite. Can you give me some advices ? Link to comment Share on other sites More sharing options...
loafer Posted May 11, 2015 Share Posted May 11, 2015 I wanted to achieve something similar. What worked for me was to create ALL possible tileSprites and setting their visible attribute to false. I added all sprites that should be displayed on top of them and could then set to tileSprite I wanted to show to visible=true and all others to visible=false. Link to comment Share on other sites More sharing options...
XekeDeath Posted May 11, 2015 Share Posted May 11, 2015 Create a group as the very first thing you do, add that to the game, and add your tilesprite to that...When you want to change the tilesprite, add it to the same group, and it will be behind everything else that you created afterwards. Link to comment Share on other sites More sharing options...
psyked Posted May 12, 2015 Author Share Posted May 12, 2015 thank you XekeDeath, your method works well and uses less ressources than recreate all layers or load all of my Tiles Link to comment Share on other sites More sharing options...
Recommended Posts