Hello all,Please Help me!....How to remove Graphics in Corona SDK? Cannot Remove Graphics in Corona SDK

Hi all,

 

I would like to know how to remove graphics when I press on a button.

post-415194-0-53293400-1369822849_thumb.When I press “My Settings” Button,I want to remove “Select Player” graphics at the right hand side panel.When I press “Select Player”,I want to remove “My Settings” graphics at the right hand side panel.
post-415194-0-40243100-1369823216_thumb.…But I cannot remove object like this…
post-415194-0-15277700-1369823242_thumb.

 

My code (in order to remove graphics) are as follows,

 

local function spButtonEvent( event )

local btn = event.target

if event.phase == “press” then

transition.to(panel, { time=400, rotation=360})

if panelWelcome ~= nil then 

panelWelcome:removeSelf()

panelWelcome = nil

if animation1~= nil then

animation1:removeSelf()

animation1 = nil

end

 if animation2~= nil then

animation2:removeSelf()

animation2 = nil

end

if animation3~= nil then

animation3:removeSelf()

animation3 = nil

end

if audioSettingTitle~=nil then

audioSettingTitle:removeSelf()

audioSettingTitle = nil

end

if voiceSlider~=nil then

voiceSlider.isVisible = false

voiceSlider= nil

end

if soundEffectsSlider~=nil then

soundEffectsSlider:removeSelf()

soundEffectsSlider = nil

end

if backgroundmusicSlider~= nil then

backgroundmusicSlider:removeSelf()

backgroundmusicSlider = nil

end

if fbLogOnButton ~= nil then

fbLogOnButton:removeSelf()

fbLogOnButton = nil

end

if pwdOnButton ~= nil then

pwdOnButton:removeSelf()

pwdOnButton = nil

end

if editMyProfileButtonSheet~= nil then

editMyProfileButton.isVisible = false

end

if adjustYourSettingMascot~= nil then

adjustYourSettingMascot:removeSelf()

adjustYourSettingMascot = nil

end

end

local spButton = widget.newButton{

id = “selectPlayerButton”,

width = 132*Xa, height = 164*Ya,

onEvent = spButtonEvent

}

 spButton.x = displayOffsetX(565,offsetx)

  spButton.y = displayOffsetY(500,offsety1,offsety2)

spButton.alpha = 0.01

May I know how to remove graphics properly in Corona SDK?..Please see the attached images.Please guide me…Thanks a lot!!!..

 

Warm Wishes,

John

 

I think it’s pretty unefficient to create and remove the objects every time.

Just create a display group for every menu. When you press the button,

simply use the group.isVisible = false or group.isVisible = true propertie.

Hi 

@torbenratzlaff,  

I will try as you mention.Thanks…

Please post your code using the and tags (no space) to make your code more readable.

Hi all,

 

I would like to know how to remove group graphics.I tried to remove display group using isVisible = false or removeSelf() but I am not able to remove and not visible.

post-415194-0-53293400-1369822849_thumb.When I press “My Settings” Button,I want to remove “Select Player” display group at the right hand side panel and then display the My Settings Display Group at the right hand side panel.When I press “Select Player”,I want to remove “My Settings” display group at the right hand side panel and then display “Select Player” display groups again.
post-415194-0-40243100-1369823216_thumb.But I cannot remove and not visible  like this…
post-415194-0-15277700-1369823242_thumb.

I have attached my code as below,

 

 

local function spButtonEvent( event ) local btn = event.target   if event.phase == "press" then   transition.to(panel, { time=400, rotation=360})   if panelWelcome ~= nil then  panelWelcome:removeSelf() panelWelcome = nil  end if animation1~= nil then animation1:removeSelf() animation1 = nil end    if animation2~= nil then animation2:removeSelf() animation2 = nil end   if animation3~= nil then animation3:removeSelf() animation3 = nil end   if audioSettingTitle~=nil then audioSettingTitle:removeSelf() audioSettingTitle = nil end   if voiceSlider~=nil then voiceSlider.isVisible = false voiceSlider= nil end   if soundEffectsSlider~=nil then soundEffectsSlider:removeSelf() soundEffectsSlider = nil end     if backgroundmusicSlider~= nil then backgroundmusicSlider:removeSelf() backgroundmusicSlider = nil end   if fbLogOnButton ~= nil then fbLogOnButton:removeSelf() fbLogOnButton = nil end   if pwdOnButton ~= nil then pwdOnButton:removeSelf() pwdOnButton = nil end   if editMyProfileButtonSheet~= nil then editMyProfileButton.isVisible = false end   if adjustYourSettingMascot~= nil then adjustYourSettingMascot:removeSelf() adjustYourSettingMascot = nil end local spButton = widget.newButton{ id = "selectPlayerButton",   width = 132\*Xa, height = 164\*Ya, onEvent = spButtonEvent }  spButton.x = displayOffsetX(565,offsetx)   spButton.y = displayOffsetY(500,offsety1,offsety2) spButton.alpha = 0.01

 

 

Your advise will be appreciate.Thanks a lot!!!..

 

Warm Wishes,

John

@apple

a few things: using multiple if statements like this will slow down your program, I am assuming all that code is for the current scene and only one of those statements ever gets executed at a single time. 

  if voiceSlider~=nil then voiceSlider.isVisible = false voiceSlider= nil elseif soundEffectsSlider~=nil then soundEffectsSlider:removeSelf() soundEffectsSlider = nil end  

that’s just an example I made using a block of your code, hopefully I am not crazy when saying that it’s “better” than what you currently have. 

Also there’s a lot of code duplication when it comes to removing an object (though you’re doing it correctly, minimizing memory leaks) 

you should take all that code that removes an object and place it inside a function to make it look neater

  local function removeDisplayObject ( objectToRemove )      display.remove( objectToRemove )    objectToRemove = nil   end

when using removeSelf, it doesn’t do a check to see if the object is already nil, so display.remove is the better choice here.

So now your code would look like 

if voiceSlider~=nil then  removeDisplayObject(voiceSlider) elseif soundEffectsSlider~=nil then  removeDisplayObject(soundEffectSlider) end

Now to answer your question, if you placed things in a display group

group:remove(PlayerSettings)  PlayerSettings = nil

should solve your problem, if you placed things into the appropriate group

I think it’s pretty unefficient to create and remove the objects every time.

Just create a display group for every menu. When you press the button,

simply use the group.isVisible = false or group.isVisible = true propertie.

Hi 

@torbenratzlaff,  

I will try as you mention.Thanks…

Please post your code using the and tags (no space) to make your code more readable.

Hi all,

 

I would like to know how to remove group graphics.I tried to remove display group using isVisible = false or removeSelf() but I am not able to remove and not visible.

post-415194-0-53293400-1369822849_thumb.When I press “My Settings” Button,I want to remove “Select Player” display group at the right hand side panel and then display the My Settings Display Group at the right hand side panel.When I press “Select Player”,I want to remove “My Settings” display group at the right hand side panel and then display “Select Player” display groups again.
post-415194-0-40243100-1369823216_thumb.But I cannot remove and not visible  like this…
post-415194-0-15277700-1369823242_thumb.

I have attached my code as below,

 

 

local function spButtonEvent( event ) local btn = event.target   if event.phase == "press" then   transition.to(panel, { time=400, rotation=360})   if panelWelcome ~= nil then  panelWelcome:removeSelf() panelWelcome = nil  end if animation1~= nil then animation1:removeSelf() animation1 = nil end    if animation2~= nil then animation2:removeSelf() animation2 = nil end   if animation3~= nil then animation3:removeSelf() animation3 = nil end   if audioSettingTitle~=nil then audioSettingTitle:removeSelf() audioSettingTitle = nil end   if voiceSlider~=nil then voiceSlider.isVisible = false voiceSlider= nil end   if soundEffectsSlider~=nil then soundEffectsSlider:removeSelf() soundEffectsSlider = nil end     if backgroundmusicSlider~= nil then backgroundmusicSlider:removeSelf() backgroundmusicSlider = nil end   if fbLogOnButton ~= nil then fbLogOnButton:removeSelf() fbLogOnButton = nil end   if pwdOnButton ~= nil then pwdOnButton:removeSelf() pwdOnButton = nil end   if editMyProfileButtonSheet~= nil then editMyProfileButton.isVisible = false end   if adjustYourSettingMascot~= nil then adjustYourSettingMascot:removeSelf() adjustYourSettingMascot = nil end local spButton = widget.newButton{ id = "selectPlayerButton",   width = 132\*Xa, height = 164\*Ya, onEvent = spButtonEvent }  spButton.x = displayOffsetX(565,offsetx)   spButton.y = displayOffsetY(500,offsety1,offsety2) spButton.alpha = 0.01

 

 

Your advise will be appreciate.Thanks a lot!!!..

 

Warm Wishes,

John

@apple

a few things: using multiple if statements like this will slow down your program, I am assuming all that code is for the current scene and only one of those statements ever gets executed at a single time. 

  if voiceSlider~=nil then voiceSlider.isVisible = false voiceSlider= nil elseif soundEffectsSlider~=nil then soundEffectsSlider:removeSelf() soundEffectsSlider = nil end  

that’s just an example I made using a block of your code, hopefully I am not crazy when saying that it’s “better” than what you currently have. 

Also there’s a lot of code duplication when it comes to removing an object (though you’re doing it correctly, minimizing memory leaks) 

you should take all that code that removes an object and place it inside a function to make it look neater

  local function removeDisplayObject ( objectToRemove )      display.remove( objectToRemove )    objectToRemove = nil   end

when using removeSelf, it doesn’t do a check to see if the object is already nil, so display.remove is the better choice here.

So now your code would look like 

if voiceSlider~=nil then  removeDisplayObject(voiceSlider) elseif soundEffectsSlider~=nil then  removeDisplayObject(soundEffectSlider) end

Now to answer your question, if you placed things in a display group

group:remove(PlayerSettings)  PlayerSettings = nil

should solve your problem, if you placed things into the appropriate group