toBack() question

Hi, im having some problems trying to make this work.
I have a background, and a button to change the background.
The default background is just a variable and the other ones (3) are a table. Whenever i press the button de background should change.

I tried using

[lua]backTable:toBack()
background:toBack()[/lua]

and it worked fine, for the first one… the next one doesn’t work because i dont know how to acces the background i just created, wich stay there at the background and the next ones are created behind him, instead of above him (and behind all the other content)
Any advice? [import]uid: 108461 topic_id: 21124 reply_id: 321124[/import]

Hey Undecode!

You can do 2 things. you can either have all 4 backgrounds already on the screen in the starting order and then push them back using toBack() as you did.
The other way, is showing only the correct background each time and hiding the rest.

I would use a table made of display.newImageRect objects for the backgrounds like so -

local currentBack = 1;  
  
local backgrounds = {};  
backgrounds[1] = display.newImageRect().....   
backgrounds[2] = display.newImageRect().....   
backgrounds[3] = display.newImageRect().....   
backgrounds[4] = display.newImageRect().....   
  
-- Hide all backgrounds except the currentBack  
  
for (i=1,4,i+1) do backgrounds[i].isVisible = true; end;  
  
backgrounds[currentBack].isVisible = true;  
  
function showBack( back\_id )  
  
if( back == NULL) then return 0;  
  
backgrounds[currentBack].isVisible = false;  
backgrounds[back\_id].isVisible = true;  
  
end;  

This code is from memory only and not tested but thats the way I do it.

Shahar [import]uid: 13553 topic_id: 21124 reply_id: 83569[/import]