Transitioning Scenes But Text Not Clearing

Transition from the menu scene to the game scene with a button. When the button is pressed the menu transitions to the game scene, but the text from the menu scene is not clearing. The button is cleared, but not the text. Expected to have a blank state to work with.

function scene:create( event ) local sceneGroup = self.view -- Add scene display objects to this group -- fill the background to a color local background = display.newRect( sceneGroup, 0, 0, actualWidth, actualHeight) background.x = width \* 0.5 background.y = height \* 0.5 background:setFillColor( 208/255,244/255,247/255 ) -- gametitle on the top center local titleText = { text = "Game Title", x = actualWidth / 2, y = actualHeight / 4, width = 100, height = 200, font = native.systemFont, fontsize = 50, align = "center" } local gameTitle = display.newText( titleText ) gameTitle:setFillColor( 0.6, 0.4, 0.8 )   -- scene transition to game button local function onPlayTouch( event ) if ( "ended" == event.phase ) then composer.gotoScene( "scene.game", "slideLeft" ) end end local playButton = widget.newButton { defaultFile = "scene/menu/ui/touch.png", onEvent = onPlayTouch } playButton.x = actualWidth / 2 playButton.y = actualHeight / 2 sceneGroup:insert( playButton ) end

The game.lua file is the just the composer template. The rest of the menu.lua code is also the composer template.

I’m not sure what you want. Maybe this helps: add parent parameter to titleText table

local titleText = { parent = sceneGroup, text = "Game Title", x = actualWidth / 2, y = actualHeight / 4, width = 100, height = 200, font = native.systemFont, fontsize = 50, align = "center" }

Thanks, Idurniat! That solved my problem. 

Please correct me if I’m wrong, but I’m guessing that by not attaching it to the current scene as its parent, it carries itself over to other scenes. So when the menu scene cleans itself up the text isn’t destroyed because it’s not identified as being part of the menu scene and carries over to the game scene.  

I think you are right:) From documentation

Remember that you must insert scene display objects into the scene’s self.view group. If you create display objects but do not insert them into this group, they will reside in front of the Composer stage and they will not be regarded as part of the scene. For display objects which should be part of the scene and “managed” by Composer — for example, cleaned up when the scene is removed — you must insert them into the scene’s self.view group, for instance:

I recommended you read more about Composer.

Thanks, I will do that. Will need to read up all I can and create the game that I really want. Thanks for your help! :smiley:

I’m not sure what you want. Maybe this helps: add parent parameter to titleText table

local titleText = { parent = sceneGroup, text = "Game Title", x = actualWidth / 2, y = actualHeight / 4, width = 100, height = 200, font = native.systemFont, fontsize = 50, align = "center" }

Thanks, Idurniat! That solved my problem. 

Please correct me if I’m wrong, but I’m guessing that by not attaching it to the current scene as its parent, it carries itself over to other scenes. So when the menu scene cleans itself up the text isn’t destroyed because it’s not identified as being part of the menu scene and carries over to the game scene.  

I think you are right:) From documentation

Remember that you must insert scene display objects into the scene’s self.view group. If you create display objects but do not insert them into this group, they will reside in front of the Composer stage and they will not be regarded as part of the scene. For display objects which should be part of the scene and “managed” by Composer — for example, cleaned up when the scene is removed — you must insert them into the scene’s self.view group, for instance:

I recommended you read more about Composer.

Thanks, I will do that. Will need to read up all I can and create the game that I really want. Thanks for your help! :smiley: