Question about display groups and their childs

Hi all!
F.e. I’ve following code:

localGroup = display:newGroup()  
  
function setBackground()  
 local background = display.newImage("assets/images/background\_game.png",true)  
 background.x = display.contentWidth / 2  
 background.y = display.contentHeight / 2  
 localGroup:insert(background)  
 background:addEventListener("touch",background\_onTouch)  
 background:toBack()  
end  
  
function new()  
 localGroup = display:newGroup()  
 setBackground()   
end   
  
function newGameButton\_ontouch(event)  
 new()  
end  

So i can click newGameButton so many times i want, the localGroup set to new empty group, but what about their child? It also deleted from the memory and from the stage automatically? Or it would be several instances of background display object in memory and on the stage? Thanks!

[import]uid: 128952 topic_id: 23357 reply_id: 323357[/import]

You should be doing this :

[code]
local localGroup = display.newGroup()

function setBackground()
local background = display.newImage(“assets/images/background_game.png”,true)
background.x = display.contentWidth / 2
background.y = display.contentHeight / 2
localGroup:insert(background)
background:addEventListener(“touch”,background_onTouch)
background:toBack()
end

function new()
display.remove(localGroup)
localGroup = display.newGroup()
setBackground()
end

function newGameButton_ontouch(event)
new()
end [import]uid: 84637 topic_id: 23357 reply_id: 93586[/import]

A syntax note: It should be display.newGroup(), with a period rather than a colon.

And you should probably check to see whether localGroup.numChildren > 0 and remove any child display objects in the group and any attached listener before adding a new background. [import]uid: 1560 topic_id: 23357 reply_id: 93588[/import]

Thank you! You help me a lot. [import]uid: 128952 topic_id: 23357 reply_id: 94074[/import]