I’m building an app using CoronaCards that has 3 scenes and I have no problem transitioning between the scenes when I test it in the Corona Simulator, but when I build the app and run it on a mobile device, the scene:create function of the second scene executes, but the background and button from the previous scene are still displayed.
My code (simplified) is basically:
main.lua
local composer = require( "composer" ) math.randomseed(os.time()) composer.gotoScene("splash")
splash.lua
local composer = require( "composer" ) local widget = require("widget") local scene = composer.newScene() -- ----------------------------------------------------------------------------------- -- Code outside of the scene event functions below will only be executed ONCE unless -- the scene is removed entirely (not recycled) via "composer.removeScene()" -- ----------------------------------------------------------------------------------- function handlePlayButton(event) local phase = event.phase if phase == "ended" then print("Play button pressed") composer.gotoScene("play") end end -- ----------------------------------------------------------------------------------- -- Scene event functions -- ----------------------------------------------------------------------------------- -- create() function scene:create( event ) local sceneGroup = self.view -- Code here runs when the scene is first created but has not yet appeared -- on screen print("In splash scene") local background = display.newImageRect("img/splash\_background.jpg", display.contentWidth, display.contentHeight) background.x = display.contentCenterX background.y = display.contentCenterY sceneGroup:insert(background) local playButton = widget.newButton { parent = self.view, left = 749, top = 369, width = 528, height = 297, defaultFile = "img/play\_button.png", onEvent = handlePlayButton, } sceneGroup:insert(playButton) end -- show() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen end end -- hide() function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) print("splash phase hide - will") composer.removeScene("splash") elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen print("splash phase hide - did") end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene
play.lua
local composer = require( "composer" ) local widget = require("widget") local scene = composer.newScene() -- ----------------------------------------------------------------------------------- -- Code outside of the scene event functions below will only be executed ONCE unless -- the scene is removed entirely (not recycled) via "composer.removeScene()" -- ----------------------------------------------------------------------------------- function handleRevealButton(event) local phase = event.phase if phase == "ended" then print("Reveal button pressed") composer.gotoScene("win", {time=800, effect="crossFade"}) end end -- ----------------------------------------------------------------------------------- -- Scene event functions -- ----------------------------------------------------------------------------------- -- create() function scene:create( event ) print("In play scene") local sceneGroup = self.view -- Code here runs when the scene is first created but has not yet appeared on screen local background = display.newImageRect("img/play\_background.jpg", display.contentWidth, display.contentHeight) background.x = display.contentCenterX background.y = display.contentCenterY sceneGroup:insert(background) print("width/height" .. display.contentWidth .. "/" .. display.contentHeight) local revealButton = widget.newButton { parent = self.view, left = 749, top = 369, width = 475, height = 152, defaultFile = "img/reveal\_button.png", onEvent = handleRevealButton, } sceneGroup:insert(revealButton) end -- show() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen end end -- hide() function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene
and the output in logcat is:
09-20 19:00:19.709 17322-17372/com.lindelsee.tapcentive_tapdemo_android I/Corona: Play button pressed
09-20 19:00:19.709 17322-17372/com.lindelsee.tapcentive_tapdemo_android I/Corona: splash phase hide - will
09-20 19:00:19.713 17322-17372/com.lindelsee.tapcentive_tapdemo_android I/Corona: In play scene
09-20 19:00:19.717 17322-17372/com.lindelsee.tapcentive_tapdemo_android I/Corona: width/height1920/1008
but the splash screen and button are still displayed instead of them disappearing and the play and reveal buttons being displayed.