Hi, I’m a corona newbie. I’ve already searched through the forums and didn’t find any questions similar to mine so I guess I must have fouled something up. I’m having issues with an app I’m working on where widgets are not displaying on a sub-scene after transitioning from the main app screen after launch.
Here’s my main app screen; menu.lua (using the game template)
----------------------------------------------------------------------------------------- -- -- menu.lua -- ----------------------------------------------------------------------------------------- local storyboard = require( "storyboard" ) local scene = storyboard.newScene() -- include Corona's "widget" library local widget = require "widget" -- include Corona's sprite library local sprite = require("sprite") -------------------------------------------- -- forward declarations and other locals local continueBtn local newGameBtn local highscoresBtn local exitBtn local settingsBtn local helpBtn local audioToggleBtn --local bgSound = audio.loadSound("sounds/title.wav") local clickSound = audio.loadSound("sounds/click.wav") local function onContinueBtnRelease() -- go to map.lua scene audio.play(clickSound) storyboard.gotoScene( "map", "fade", 500, {continue=true} ) return true -- indicates successful touch end -- 'onRelease' event listener for Buttons local function onNewGameBtnRelease() -- go to map.lua scene audio.play(clickSound) storyboard.gotoScene( "map", "fade", 500 ) return true -- indicates successful touch end local function onHighScoresBtnRelease() -- go to map.lua scene audio.play(clickSound) storyboard.gotoScene( "highscores", "fade", 500 ) return true -- indicates successful touch end local function onSettingsBtnRelease() -- go to map.lua scene audio.play(clickSound) storyboard.gotoScene( "settings", "fade", 500 ) return true -- indicates successful touch end local function onHelpBtnRelease() -- go to map.lua scene audio.play(clickSound) storyboard.gotoScene( "help", "fade", 500 ) return true -- indicates successful touch end local function onAudioToggleBtnRelease() -- go to map.lua scene --TODO: put in global settings to disable audio return true -- indicates successful touch end local function onExitBtnRelease() native.requestExit() end ----------------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION -- -- NOTE: Code outside of listener functions (below) will only be executed once, -- unless storyboard.removeScene() is called. -- ----------------------------------------------------------------------------------------- -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view audio.play(bgSound, {loops=-1}) -- display a background image local background = display.newImageRect( "images/screens/start\_screen.jpg", display.contentWidth, display.contentHeight ) background:setReferencePoint( display.TopLeftReferencePoint ) background.x, background.y = 0, 0 -- create/position logo/title image on upper-half of the screen local titleLogo = display.newImageRect( "images/danfo\_logoII.png", 480, 184 ) titleLogo:setReferencePoint( display.CenterReferencePoint ) titleLogo.x = display.contentWidth \* 0.5 titleLogo.y = display.contentHeight + titleLogo.height \* 0.5 local btnSpriteSheet = graphics.newImageSheet("images/button\_bg.png", {width=219, height=55, numFrames=3}) local iconBtnSpriteSheet = graphics.newImageSheet("images/mainmenu\_icons.png", {width=64, height=64, numFrames=6}) local roundedRect = display.newRoundedRect(4, display.contentHeight \* 0.52, display.contentWidth\*3/19, display.contentHeight\*0.45, display.contentWidth/24) roundedRect.strokeWidth = 3 roundedRect:setFillColor(32, 7, 114, 50) roundedRect:setStrokeColor(255) -- create a widget buttons continueBtn = widget.newButton{ label="CONTINUE", labelColor = { default={0}, over={255} }, font = "Helvetica", fontSize = display.contentWidth/20, emboss = true, sheet = btnSpriteSheet, defaultFrame = 1, overFrame = 3, onRelease = onContinueRelease -- event listener function } newGameBtn = widget.newButton{ label="NEW GAME", labelColor = { default={255}, over={128} }, font = "Helvetica", fontSize = display.contentWidth/20, emboss = true, sheet = btnSpriteSheet, defaultFrame = 2, overFrame = 3, onRelease = onNewGameBtnRelease -- event listener function } highscoresBtn = widget.newButton{ label="HIGH SCORES", labelColor = { default={0}, over={255} }, font = "Helvetica", fontSize = display.contentWidth/20, emboss = true, sheet = btnSpriteSheet, defaultFrame = 1, overFrame = 3, onRelease = onHighScoresBtnRelease -- event listener function } exitBtn = widget.newButton{ label="EXIT", labelColor = { default={255}, over={128} }, font = "Helvetica", fontSize = display.contentWidth/20, emboss = true, sheet = btnSpriteSheet, defaultFrame = 2, overFrame = 3, onRelease = onExitBtnRelease -- event listener function } settingsIconBtn = widget.newButton{ sheet = iconBtnSpriteSheet, defaultFrame = 1, overFrame = 2, onRelease = onSettingsBtnRelease -- event listener function } helpIconBtn = widget.newButton{ sheet = iconBtnSpriteSheet, defaultFrame = 3, overFrame = 4, onRelease = onHelpBtnRelease -- event listener function } audioToggleBtn = widget.newButton{ sheet = iconBtnSpriteSheet, defaultFrame = 5, overFrame = 5, onRelease = onAudioToggleBtnRelease -- event listener function } continueBtn:setReferencePoint( display.CenterReferencePoint ) newGameBtn:setReferencePoint( display.CenterReferencePoint ) highscoresBtn:setReferencePoint( display.CenterReferencePoint ) exitBtn:setReferencePoint( display.CenterReferencePoint ) settingsIconBtn:setReferencePoint( display.CenterReferencePoint ) helpIconBtn:setReferencePoint( display.CenterReferencePoint ) audioToggleBtn:setReferencePoint( display.CenterReferencePoint ) continueBtn.x = -continueBtn.width continueBtn.y = titleLogo.height + newGameBtn.height \* 0.5 newGameBtn.x = display.contentWidth + newGameBtn.width newGameBtn.y = titleLogo.height + newGameBtn.height \* 2 highscoresBtn.x = -highscoresBtn.width highscoresBtn.y = titleLogo.height + newGameBtn.height \* 3.5 exitBtn.x = display.contentWidth + exitBtn.width exitBtn.y = titleLogo.height + newGameBtn.height \* 5 settingsIconBtn.x = settingsIconBtn.width \* 0.64 settingsIconBtn.y = display.contentHeight \* 0.6 helpIconBtn.x = settingsIconBtn.width \* 0.64 helpIconBtn.y = display.contentHeight \* 0.6 + helpIconBtn.height \* 1.5 audioToggleBtn.x = audioToggleBtn.width \* 0.64 audioToggleBtn.y = display.contentHeight \* 0.6 + helpIconBtn.height \* 3 transition.to(titleLogo, {time=1000, transition=easing.outExpo, y=display.contentHeight \* 0.005 + titleLogo.height \* 0.5}) transition.to(continueBtn, {time=1000, transition = easing.outExpo,x=display.contentWidth\*0.55}) transition.to(newGameBtn, {time=1000, transition = easing.outExpo,x=display.contentWidth\*0.45}) transition.to(highscoresBtn, {time=1000, transition = easing.outExpo,x=display.contentWidth\*0.55}) transition.to(exitBtn, {time=1000, transition = easing.outExpo,x=display.contentWidth\*0.45}) -- all display objects must be inserted into group group:insert( background ) group:insert( titleLogo ) group:insert( continueBtn ) group:insert( newGameBtn ) group:insert( highscoresBtn ) group:insert( exitBtn ) group:insert( settingsIconBtn) group:insert( helpIconBtn ) group:insert( audioToggleBtn ) end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view -- INSERT code here (e.g. start timers, load audio, start listeners, etc.) end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view audio.stop() -- INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.) end -- If scene's view is removed, scene:destroyScene() will be called just prior to: function scene:destroyScene( event ) local group = self.view if continueBtn then continueBtn:removeSelf() -- widgets must be manually removed continueBtn = nil end if newGameBtn then newGameBtn:removeSelf() -- widgets must be manually removed newGameBtn = nil end if highscoresBtn then highscoresBtn:removeSelf() -- widgets must be manually removed highscoresBtn = nil end if exitBtn then exitBtn:removeSelf() -- widgets must be manually removed exitBtn = nil end if settingsIconBtn then settingsIconBtn:removeSelf() -- widgets must be manually removed settingsIconBtn = nil end if helpIconBtn then helpIconBtn:removeSelf() -- widgets must be manually removed helpIconBtn = nil end if audioToggleBtn then audioToggleBtn:removeSelf() -- widgets must be manually removed audioToggleBtn = nil end end ----------------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION ----------------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched whenever before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) ----------------------------------------------------------------------------------------- return scene
On line 58:menu.lua is the function for handling touch events on the help widget. However, this widget is pressed and the help screen opens, none of the widgets are visible. However, the ImageRect created on line 68:help.lua (reproduced below) is displayed without a problem.
----------------------------------------------------------------------------------------- -- -- menu.lua -- ----------------------------------------------------------------------------------------- local storyboard = require( "storyboard" ) local scene = storyboard.newScene() -- include Corona's "widget" library local widget = require "widget" -- include Corona's sprite library local sprite = require("sprite") -------------------------------------------- -- forward declarations and other locals local backBtn local leftBtn local rightBtn --local bgSound = audio.loadSound("sounds/title.wav") local clickSound = audio.loadSound("sounds/click.wav") local function onBackBtnRelease() -- go to map.lua scene audio.play(clickSound) storyboard.gotoScene( "menu", "fade", 500) return true -- indicates successful touch end -- 'onRelease' event listener for Buttons local function onLeftBtnRelease() -- go to map.lua scene audio.play(clickSound) --storyboard.gotoScene( "map", "fade", 500 ) return true -- indicates successful touch end local function onRightBtnRelease() -- go to map.lua scene audio.play(clickSound) --storyboard.gotoScene( "highscores", "fade", 500 ) return true -- indicates successful touch end ----------------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION -- -- NOTE: Code outside of listener functions (below) will only be executed once, -- unless storyboard.removeScene() is called. -- ----------------------------------------------------------------------------------------- -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view --audio.play(bgSound, {loops=-1}) -- display a background image local background = display.newImageRect( "images/screens/help\_scores\_screen.jpg", display.contentWidth, display.contentHeight ) background:setReferencePoint( display.TopLeftReferencePoint ) background.x, background.y = 0, 0 --local titleSpriteSheet = graphics.newImageSheet("images/screen\_titles.png", {width=342, height=50, numFrames=4}) local btnSpriteSheet = graphics.newImageSheet("images/button\_bg.png", {width=219, height=55, numFrames=3}) local dirBtnSpriteSheet = graphics.newImageSheet("images/help\_arrows.png", {width=24, height=32, numFrames=4}) -- create/position logo/title image on upper-half of the screen local titleText = display.newImageRect( "images/danfo\_logoII.png", 480, 184 ) titleText:setReferencePoint( display.CenterReferencePoint ) titleText.x = display.contentWidth \* 0.5 titleText.y = titleText.height \* 0.005 -- create a widget buttons backBtn = widget.newButton{ label="Back", labelColor = { default={0}, over={255} }, font = "Helvetica", fontSize = display.contentWidth/20, emboss = true, sheet = btnSpriteSheet, defaultFrame = 1, overFrame = 3, onRelease = onBackBtnRelease -- event listener function } leftBtn = widget.newButton{ sheet = dirBtnSpriteSheet, defaultFrame = 1, overFrame = 1, onRelease = onLeftBtnRelease -- event listener function } rightBtn = widget.newButton{ sheet = dirBtnSpriteSheet, defaultFrame = 1, overFrame = 1, onRelease = onRightBtnRelease -- event listener function } backBtn:setReferencePoint( display.CenterReferencePoint ) leftBtn:setReferencePoint( display.CenterReferencePoint ) rightBtn:setReferencePoint( display.CenterReferencePoint ) backBtn.x = display.contentWidth \* 0.5 backBtn.y = display.contentHeight \* 0.9 leftBtn.x = leftBtn.width \* 2 leftBtn.y = display.contentHeight \* 0.8 rightBtn.x = display.contentWidth - rightBtn.width \* 2 rightBtn.y = display.contentHeight \* 0.8 -- all display objects must be inserted into group --group:insert( titleText) group:insert( backBtn) group:insert( leftBtn ) group:insert( rightBtn ) end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view -- INSERT code here (e.g. start timers, load audio, start listeners, etc.) end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view audio.stop() -- INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.) end -- If scene's view is removed, scene:destroyScene() will be called just prior to: function scene:destroyScene( event ) local group = self.view if backBtn then backBtn:removeSelf() -- widgets must be manually removed backBtn = nil end if leftBtn then leftBtn:removeSelf() -- widgets must be manually removed leftBtn = nil end if rightBtn then rightBtn:removeSelf() -- widgets must be manually removed rightBtn = nil end end ----------------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION ----------------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched whenever before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) ----------------------------------------------------------------------------------------- return scene