– Create a scene object to tie functions to. local scene = storyboard.newScene();
– ============================================================================ – Called when the scene’s view does not exist. – ============================================================================ function scene:createScene(inEvent)
utils:log("menuScene", "createScene()"); -- Create New Game text, center it and attached event handler. local txtTitle = display.newText("Menu Scene", 0, 0, native.systemFont, 52); txtTitle.x = display.contentCenterX; txtTitle.y = display.contentCenterY - 170; txtTitle:addEventListener("touch", function(inEvent) if inEvent.phase == "ended" then utils:log("menuScene", "go to menuScene"); storyboard.gotoScene("settingsScene", "zoomOutIn", 500); end end ); self.view:insert(txtTitle);
end – End createScene().
– ============================================================================ – Called BEFORE scene has moved on screen. – ============================================================================ function scene:willEnterScene(inEvent)
utils:log("menuScene", "willEnterScene()");
end – End willEnterScene().
– ============================================================================ – Called AFTER scene has moved on screen. – ============================================================================ function scene:enterScene(inEvent)
utils:log("menuScene", "enterScene()");
end – End enterScene().
– ============================================================================ – Called BEFORE scene moves off screen. – ============================================================================ function scene:exitScene(inEvent)
utils:log("menuScene", "exitScene()"); -- Remove event listener (not tied to a specific object). Runtime:removeEventListener("touch", scene); -- Remove event listener for doing the background animation. Runtime:removeEventListener("enterFrame", scene);
end – End exitScene().
– ============================================================================ – Called AFTER scene has moved off screen. – ============================================================================ function scene:didExitScene(inEvent)
utils:log("menuScene", "didExitScene()");
end – End didExitScene().
– ============================================================================ – Called prior to the removal of scene’s “view” (display group). – ============================================================================ function scene:destroyScene(inEvent)
utils:log("menuScene", "destroyScene()");
end – End destroyScene().
– ============================================================================ – Handle touch events for this scene. – ============================================================================ function scene:touch(inEvent)
utils:log("menuScene", "touch()"); -- Only trigger when a finger is lifted. if inEvent.phase == "ended" then storyboard.gotoScene("menuScene", "crossFade", 500); end return true;
end – End touch().
– ============================================================================ – enterFrame event processing. – ============================================================================ function scene:enterFrame(inEvent)
utils:log("menuScene", "enterFrame()");
end – End enterFrame().
– Add scene lifecycle event handlers. scene:addEventListener(“createScene”, scene); scene:addEventListener(“willEnterScene”, scene); scene:addEventListener(“enterScene”, scene); scene:addEventListener(“exitScene”, scene); scene:addEventListener(“didExitScene”, scene); scene:addEventListener(“destroyScene”, scene);
return scene;