To change scenes using Widget and Director…
local function toScreen2(event) if event.phase == "ended" then display.remove(background);background=nil -- All other objects are removed. display.remove(button);button=nil -- Some how this stays eating up memory. end return true end local button = widget.newButton { width = 400, height = 75, label = "Screen1", labelColor = { default = {51,181,229,255}, over = {0, 255, 127,255} }, font = native.systemFont, fontSize = 30, onRelease = toScreen2, } button.x = display.contentCenterX button.y = 125 Group:insert(button)
In my " toScreen2" function, all objects are removed except the actual button. How do I make sure the pressed button is removed with the rest of the objects on the screen? I tried to declare my variables beforehand but to no avail. What am I doing wrong?