So I make an objects when the game is paused. But when the game is unpaused, i tried to remove the objects I made, but it doesn’t removed. I already tried to use obj:removeSelf(), obj = nil, and display.remove(obj) but nothing works. Here is my code.
if event.keyName == "back" or event.keyName == "escape" then
world.pause = true
local pausemenu = display.newImage( sceneGroup,"assets/menu/pause-menu.png", 180, 180)
pausemenu.x, pausemenu.y = 400, 150
local txtSound = display.newText("Sound ", 350, 120, "assets/fonts/Shadow of the Deads.ttf", 15)
txtSound.fill = {color.hex2rgb("#dba400")}
local txtBlood = display.newText("Blood ", 347, 155, "assets/fonts/Shadow of the Deads.ttf", 15)
txtBlood.fill = {color.hex2rgb("#dba400")}
local txtResume = display.newText("Resume ", 362, 190, "assets/fonts/Shadow of the Deads.ttf", 15)
txtResume.fill = {color.hex2rgb("#dba400")}
local txtBack = display.newText("Back", 342, 225, "assets/fonts/Shadow of the Deads.ttf", 15)
txtBack.fill = {color.hex2rgb("#dba400")}
txtBlood:addEventListener("tap", blood)
txtResume:addEventListener("tap", resume)
txtSound:addEventListener("tap", sound)
txtBack:addEventListener("tap", goBack)
print(world.pause)
print("in the event")
if not world.pause then
pausemenu = nil
txtBack:removeEventListener("tap")
txtBlood:removeEventListener("tap")
txtSound:removeEventListener("tap")
txtResume:removeEventListener("tap")
display.remove(pausemenu)
display.remove(txtBack)
display.remove(txtBlood)
display.remove(txtSound)
display.remove(txtResume)
end
end
and this is the function I made
local function goBack()
fx.fadeOut( function()
composer.gotoScene( "scenes.menu")
end )
end
local function resume()
print(world.pause)
print("before resume")
world.pause = not world.pause
print(world.pause)
print("after resume")
end
local function sound()
end
local function blood()
bblood = not bblood
end
I put the functions above before function:scene:create()