Jump to content

Dynamic background with tilesprites


psyked
 Share

Recommended Posts

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

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

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

 Share

  • Recently Browsing   0 members

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