Objects not handled by Composer scene:Show ?

Hi guys,

Not sure what i’m doing wrong here.

When entering this scene this code looks to see if the ‘key’ is in the game or not. If the variable inGame.myKey == true it shows the key, if not it doesn’t show the key.

The problem is the alpha for the key is 0.1 and each time i return to the scene the key becomes more visible, like the object isn’t properly removed and a new one is created over the top of it.

Why is this, the key is put into the sceneGroup. why isn’t it removed after i leave the scene

function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then inGame = loadsave.loadTable("inGame.json") allObjects = loadsave.loadTable("allObjects.json") function objKey() if inGame.myKey == true then local myKey = display.newImageRect("objects/Key.png", 70, 70 ) myKey.x = display.contentWidth\*0.6 myKey.y = display.contentHeight\*0.9 myKey.alpha = 0.1 sceneGroup:insert( myKey ) function myKey:touch( event ) if event.phase == "began" then myKey:removeSelf() myKey = nil inGame.myKey = false loadsave.saveTable(inGame, "inGame.json", system.DocumentsDirectory) invTrayShow() return true end end myKey:addEventListener( "touch", myKey) else --do nothing, not in game end end objKey()

very grateful for any advice!

Nathan

Display objects are added to sceneGroup in scene:create, not scene:show. 

cheers James,

i’ve created all objects in the scene:create and just shown them or not using isVisible!

Display objects are added to sceneGroup in scene:create, not scene:show. 

cheers James,

i’ve created all objects in the scene:create and just shown them or not using isVisible!