Menu button

Hello I’m working on a sample game I added a few buttons on the home page and changed a few things on level1, I also added a Menu button to level1.  The problem is after I touch the Menu button and return to the home page the word Menu appears.  I’m very happy that it almost worked, I’m getting there!  But where did I go wrong?

Menu

local composer = require( "composer" ) local scene = composer.newScene() -- include Corona's "widget" library --- local widget = require "widget" -------------------------------------------------------------------------------------------------------------- local playBtn1 local function onPlayBtn1Release() -- 'onRelease' event listener for playBtn --- composer.gotoScene( "level1", "fade", 500 ) -- go to levels\_page.lua scene --- return true -- indicates successful touch --- end ----------------------------------------------------------------------------------------------------------------- function scene:create( event ) local sceneGroup = self.view -- display a background image --- local background = display.newImageRect( "background.png", display.actualContentWidth, display.actualContentHeight ) background.anchorX = 0 background.anchorY = 0 background.x = 0 + display.screenOriginX background.y = 0 + display.screenOriginY -- create/position logo/title image on upper-half of the screen --- local titleLogo = display.newImageRect( "logo.png", 300, 40 ) -- changed logo png --- titleLogo.x = display.contentCenterX titleLogo.y = 40 ----------------------------------------------------------------------------------------------------------- playBtn1 = widget.newButton{ label="First", labelColor = { default={ 0, 0, 0}, over={128} }, defaultFile="buttonDefault1.png", overFile="buttonOver1.png", width=100, height=30, onRelease = onPlayBtn1Release -- event listener function --- } playBtn1.x = display.contentCenterX playBtn1.y = display.contentHeight - 190 ---------------------------------------------------------------------------------------------------------- playBtn2 = widget.newButton{ label="Second", labelColor = { default={ 0, 0, 0}, over={128} }, defaultFile="buttonDefault2.png", overFile="buttonOver2.png", width=100, height=30, onRelease = onPlayBtn2Release -- event listener function --- } playBtn2.x = display.contentCenterX playBtn2.y = display.contentCenterY + 20 ------------------------------------------------------------------------------------------------------------- playBtn3 = widget.newButton{ label="Third", labelColor = { default={ 0, 0, 0}, over={128} }, defaultFile="buttonDefault3.png", overFile="buttonOver3.png", width=100, height=30, onRelease = onPlayBtn3Release -- event listener function --- } playBtn3.x = display.contentCenterX playBtn3.y = display.contentCenterY + 70 -------------------------------------------------------------------------------------------------------------- -- all display objects must be inserted into group --- sceneGroup:insert( background ) sceneGroup:insert( titleLogo ) sceneGroup:insert( playBtn1 ) sceneGroup:insert( playBtn2 ) sceneGroup:insert( playBtn3 ) end -------------------------------------------------------------------------------------------------- function scene:show( event ) local sceneGroup = self.view local phase = event.phase if phase == "will" then -- Called when the scene is still off screen and is about to move on screen --- elseif phase == "did" then -- Called when the scene is now on screen --- -- -- INSERT code here to make the scene come alive --- -- e.g. start timers, begin animation, play audio, etc. --- end end ---------------------------------------------------------------------------------------------------- function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if event.phase == "will" then -- Called when the scene is on screen and is about to move off screen --- -- -- INSERT code here to pause the scene --- -- e.g. stop timers, stop animation, unload sounds, etc.) --- elseif phase == "did" then -- Called when the scene is now off screen --- end end ------------------------------------------------------------------------------------------------------- function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's "view" (sceneGroup) --- -- -- INSERT code here to cleanup the scene --- -- e.g. remove display objects, remove touch listeners, save state, etc. --- if playBtn1 then playBtn1:removeSelf() -- widgets must be manually removed --- playBtn1 = nil end end --------------------------------------------------------------------------------- -- Listener setup --- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) ----------------------------------------------------------------------------------------- return scene

Level1

local composer = require( "composer" ) local scene = composer.newScene() -- include Corona's "widget" library local widget = require "widget" -- include Corona's "physics" library local physics = require "physics" -------------------------------------------------------------------------------------------------------------------------------- -- forward declarations and other locals local screenW, screenH, halfW = display.actualContentWidth, display.actualContentHeight, display.contentCenterX function scene:create( event ) local sceneGroup = self.view -- We need physics started to add bodies, but we don't want the simulaton -- running until the scene is on the screen. physics.start() physics.pause() -------------------------------------------------------------------------------------------- local function onMenuTouch(event) if(event.phase == "ended") then composer.gotoScene("menu", "slideRight") end end ---------------------------------------------------------------------------------------------- -- display a worldBK image --- local worldBK = display.newImageRect( "worldBK.jpg", display.actualContentWidth, display.actualContentHeight ) worldBK.anchorX = 0 worldBK.anchorY = 0 worldBK.x = 0 + display.screenOriginX worldBK.y = 0 + display.screenOriginY --------------------------------------------------------------------------------------------- txt\_menu = display.newText("Menu", 0, 0, native.systemFont, 25) txt\_menu.x = 15 txt\_menu.y = 15 txt\_menu:setFillColor( 255, 0, 0 ) txt\_menu:addEventListener("touch", onMenuTouch) ---------------------------------------------------------------------------------------------- --make a crate (off-screen), position it, and rotate slightly local crate = display.newImageRect( "crate.png", 90, 90 ) crate.x, crate.y = 160, -100 crate.rotation = 15 --add physics to the crate physics.addBody( crate, { density=1.0, friction=0.3, bounce=0.3} ) --create a grass object and add physics (with custom shape) local grass = display.newImageRect( "grass.png", screenW, 82 ) grass.anchorX = 0 grass.anchorY = 1 -- draw the grass at the very bottom of the screen grass.x = display.screenOriginX grass.y = display.actualContentHeight + 55 --define a shape that's slightly shorter than image bounds (set draw mode to "hybrid" or "debug" to see) local grassShape = { -halfW,-34, halfW,-34, halfW,34, -halfW,34 } physics.addBody( grass, "static", { friction=0.3, shape=grassShape } ) --all display objects must be inserted into group sceneGroup:insert( worldBK ) sceneGroup:insert( grass) sceneGroup:insert( crate ) end ----------------------------------------------------------------------------------------------------- function scene:show( event ) local sceneGroup = self.view local phase = event.phase if phase == "will" then -- Called when the scene is still off screen and is about to move on screen elseif phase == "did" then -- Called when the scene is now on screen -- -- INSERT code here to make the scene come alive -- e.g. start timers, begin animation, play audio, etc. physics.start() end end ------------------------------------------------------------------------------------------------------------ function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if event.phase == "will" then -- Called when the scene is on screen and is about to move off screen -- -- INSERT code here to pause the scene -- e.g. stop timers, stop animation, unload sounds, etc.) physics.stop() elseif phase == "did" then -- Called when the scene is now off screen end end --------------------------------------------------------------------------------------------------------------- function scene:destroy( event ) -- Called prior to the removal of scene's "view" (sceneGroup) -- -- INSERT code here to cleanup the scene -- e.g. remove display objects, remove touch listeners, save state, etc. local sceneGroup = self.view package.loaded[physics] = nil physics = nil end ---------------------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) ----------------------------------------------------------------------------------------- return scene

Appreciate any help, 

Thanks

On lines 44-50 of your level1.lua file where you create the menu text, it hasn’t been added to a scene display group so therefore it’s not being removed on scene change.

Thank you for helping me.  You and everyone here at the forum are always so willing to help us, you’re all really AWESOME!!

Thanks again.

On lines 44-50 of your level1.lua file where you create the menu text, it hasn’t been added to a scene display group so therefore it’s not being removed on scene change.

Thank you for helping me.  You and everyone here at the forum are always so willing to help us, you’re all really AWESOME!!

Thanks again.