--------------------------------------------------------------------------------- -- -- scene1.lua -- --------------------------------------------------------------------------------- local sceneName = ... local composer = require( "composer" ) -- Load scene with same root filename as this file local scene = composer.newScene( sceneName ) --------------------------------------------------------------------------------- local nextSceneButton local selectNewLogo local logo --local userLogoExists = false --local logoGroup function scene:create( event ) local sceneGroup = self.view -- Called when the scene's view does not exist -- -- INSERT code here to initialize the scene -- e.g. add display objects to 'sceneGroup', add touch listeners, etc end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if phase == "will" then trumpFace = self:getObjectByName("trump") trumpFace.isVisible = false -- Called when the scene is still off screen and is about to move on screen local logoPath = system.pathForFile( "userLogo.jpg", system.DocumentsDirectory ) local logoFile = io.open(logoPath) if logoFile then --trumpFace.isVisible = false logo = nil logo = display.newImage("userLogo.jpg", system.DocumentsDirectory) io.close(logoFile) logoFile = nil logo:scale(.15,.15) logo.x = display.contentWidth/2 logo.y = display.contentHeight/2 logo.new = true else trumpFace.isVisible = true logo = trumpFace logo.new = false end sceneGroup:insert(logo) goBtn = self:getObjectByName("goBtn") function goBtn:tap (event) composer.gotoScene( "scene2")--, {effect = "fade", time = 300}) return true end goBtn:addEventListener("tap", goBtn) elseif phase == "did" then local function onComplete( event ) if event.completed == false then event.completed = true print(event.completed) end end -- 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 -- we obtain the object by id from the scene's object hierarchy if logo.new == false then selectNewLogo = logo sceneGroup:insert(selectNewLogo) if selectNewLogo then function selectNewLogo:touch (event) local phase = event.phase if phase == "ended" then if media.hasSource( media.PhotoLibrary ) then media.selectPhoto( { mediaSource=media.PhotoLibrary, destination = { baseDir= system.DocumentsDirectory, filename= "userLogo.jpg", type = "image"}, listener=onComplete } ) else native.showAlert( "Corona", "This device does not have a photo library.", { "OK" } ) end end --composer.gotoScene( "scene1")--,{effect = "fade", time = 300}) end selectNewLogo:addEventListener("touch", selectNewLogo) end end end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if event.phase == "will" then print("will") --logo.isVisible = false if selectNewLogo then selectNewLogo:removeEventListener("touch", selectNewLogo) end -- 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 -- if nextSceneButton then -- nextSceneButton:removeEventListener( "touch", nextSceneButton ) -- end 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 end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene
--------------------------------------------------------------------------------- -- -- scene3.lua -- --------------------------------------------------------------------------------- local sceneName = ... local sqlite3 = require( "sqlite3" ) local json = require("json") local composer = require( "composer" ) -- Load scene with same root filename as this file local scene = composer.newScene( sceneName ) --------------------------------------------------------------------------------- local nextSceneButton function scene:create( event ) local sceneGroup = self.view -- Called when the scene's view does not exist -- -- INSERT code here to initialize the scene -- e.g. add display objects to 'sceneGroup', add touch listeners, etc 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 t = {} local goToScene1Btn = self:getObjectByName( "GoToScene1Btn" ) goToScene1Btn.x = display.contentWidth - 95 goToScene1Btn.y = display.contentHeight - 35 local goToScene1Text = self:getObjectByName( "GoToScene1Text" ) goToScene1Text.x = display.contentWidth - 92 goToScene1Text.y = display.contentHeight - 35 local db = sqlite3.open\_memory() db:exec[[CREATE TABLE test (id INTEGER PRIMARY KEY, content);]] print( "version " .. sqlite3.version() ) for row in db:nrows("SELECT \* FROM test") do t[row.id] = display.newText( row.content, display.contentWidth/2, 30\*row.id, nil, 16 ) t[row.id]:setFillColor( 1, 0, 1 ) sceneGroup:insert(t[row.id]) end -- text field for task name local taskName = display.newText("Task Name",display.contentWidth/2, (display.contentHeight/2)-50, native.systemFont ) taskName:setFillColor{0,0,0} local fieldBG = display.newRect(display.contentWidth/2, display.contentHeight/2 , display.contentWidth-96, 20) local paint = { 0, 0, 0 } fieldBG.fill = paint titleField = native.newTextField( display.contentWidth/2, display.contentHeight/2 , display.contentWidth-100, 16) --text field for task details local taskDetails = display.newText("Task Details",display.contentWidth/2, (display.contentHeight/2)+50, native.systemFont ) taskDetails:setFillColor{0,0,0} local fieldBG2 = display.newRect(display.contentWidth/2, (display.contentHeight/2) + 100, display.contentWidth-96, 20) fieldBG2.fill = paint detailField = native.newTextField( display.contentWidth/2, (display.contentHeight/2) + 100, display.contentWidth-100, 16) --task submission button taskSubmitBtn = display.newRect(display.contentWidth/2, (display.contentHeight/2) + 150, display.contentWidth/4, 40) sceneGroup:insert(taskSubmitBtn) local paint = { 0, 0, 0 } taskSubmitBtn.fill = paint local SubmitBtnText = display.newText("Add Task",display.contentWidth/2, (display.contentHeight/2)+ 150, native.systemFont ) taskDetails:setFillColor{0,0,0} function taskSubmitBtn:touch (event) if event.phase == "ended" then taskTable = {} taskTable[#taskTable+1] = { taskTitle = titleField.text, taskDetails = detailField.text } print(taskTable[#taskTable].taskTitle) print(taskTable[#taskTable].taskDetails) end end taskSubmitBtn:addEventListener("touch", taskSubmitBtn) sceneGroup:insert(taskName) sceneGroup:insert(fieldBG) sceneGroup:insert(taskDetails) sceneGroup:insert(fieldBG2) sceneGroup:insert(taskSubmitBtn) sceneGroup:insert(SubmitBtnText) elseif phase == "did" then -- print("did") -- 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 nextSceneButton = self:getObjectByName( "GoToScene1Btn" ) if nextSceneButton then -- touch listener for the button function nextSceneButton:touch ( event ) if "ended" == event.phase then composer.gotoScene( "scene1")--, { effect = "fade", time = 300 } ) return true end end -- add the touch event listener to the button nextSceneButton:addEventListener( "touch", nextSceneButton ) end end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if event.phase == "will" then if titleField then titleField.isVisible = false -- titleField:removeSelf() --titleField = nil end if detailField then detailField.isVisible = false --detailField:removeSelf() --detailField = nil end -- titleField.isVisible = false -- detailField.isVisible = false --detailField:removeSelf() -- for i=1 , #t, 1 do -- t[i].isVisible = false -- end -- 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 --if nextSceneButton then taskSubmitBtn:removeEventListener("touch", taskSubmitBtn) nextSceneButton:removeEventListener( "touch", nextSceneButton ) --end 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 end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene
--------------------------------------------------------------------------------- -- -- scene2.lua -- --------------------------------------------------------------------------------- local sceneName = ... local composer = require( "composer" ) -- Load scene with same root filename as this file local scene = composer.newScene( sceneName ) --------------------------------------------------------------------------------- local nextSceneButton function scene:create( event ) local sceneGroup = self.view -- Called when the scene's view does not exist -- -- INSERT code here to initialize the scene -- e.g. add display objects to 'sceneGroup', add touch listeners, etc 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 local title = self:getObjectByName( "Title" ) title.x = display.contentWidth / 2 title.y = display.contentHeight / 2 title.size = display.contentWidth / 10 local goToScene3Btn = self:getObjectByName( "GoToScene3Btn" ) goToScene3Btn.x = display.contentWidth - 95 goToScene3Btn.y = display.contentHeight - 35 local goToScene3Text = self:getObjectByName( "GoToScene3Text" ) goToScene3Text.x = display.contentWidth - 92 goToScene3Text.y = display.contentHeight - 35 nextSceneButton = self:getObjectByName( "GoToScene3Btn" ) 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 if nextSceneButton then -- touch listener for the button function nextSceneButton:touch ( event ) local phase = event.phase if phase == "ended" then composer.gotoScene( "scene3")--, { effect = "fade", time = 300 } ) print("go to 3") end return true end -- add the touch event listener to the button nextSceneButton:addEventListener( "touch", nextSceneButton ) end 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 if nextSceneButton then nextSceneButton:removeEventListener( "touch", nextSceneButton ) end 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 end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene
Thank you for the responses. I have looked at the event handler phases but didn’t recognize anything that may cause a problem. The issue arises after I have looped through the scenes 3 times. As you can see, most of this is just cut and pasted sample code. Sorry for posting so much erroneous code. I am just not sure where the problem is.