Question

I am very new to Corona.

In my game, i would like to have a menu with several options (like "single player" or "settings"). When tapping any of those options that screen fades away and a new one appears.

This next screen (after tapping "single player" for example) should have some text like "Choose your character" and once the user taps their character, another screen fades in, etc.

I wanted to know if what I'm talking about are called scenes, if not, what are they and how do they work?

Please feel free to explain, or if it's too much, post a link to an understandable source, like another stack overflow question or a youtube video.

One more thing, is it possible to have the user swipe the screen, which would trigger an event that takes him/her back to a different screen/scene?

Was it helpful?

Solution

Here is the link to understand the storyboard of corona : Corona storyboard

And yes you can use a swipe event to trigger screen pagination. For that,refer this question: How to slide pages in Corona SDK

OTHER TIPS

The current scene manager that corona supports is composer (storyboard is deprecated and will become unavailable in the future)

Scenes in corona are managed and handled by composer

Here is a link to the composer tutorial

Each scene has the following events it responds to:

  • create
  • show
  • hide
  • destroy

The key to understanding the lifecycle of a scene you need to remember that the create event only gets called once, until the scene is destroyed.

The event show gets called everytime the scene is shown

The event hide gets called eveytime the scene is dismissed.

The event destroy gets called only when the OS decides to get rid of that scene's memory. This might not happen until you exit from your app.

Yes, all that plan can be done using scenes, for an orgized game.

For every scene, you can follow this recommended format at the end of this page. I'll type it here at the end of this answer.

Once you have the scenes, you call them with:

storyboard.gotoScene("name_Of_The_Scene")

and to erase the scene

storyboard.purgeScene("name_Of_The_Scene")

I think you can implement the swipe effect using touch events of corona (They are very easy to use). In my case I use buttons with transitions effects between scenes.

Recommended format for the scene

(For copying and pasting)

local storyboard = require( "storyboard" )
local scene = storyboard.newScene()

----------------------------------------------------------------------------------
-- 
--      NOTE:
--      
--      Code outside of listener functions (below) will only be executed once,
--      unless storyboard.removeScene() is called.
-- 
---------------------------------------------------------------------------------


-- local forward references should go here --


---------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------

-- Called when the scene's view does not exist:
function scene:createScene( event )
        local group = self.view

    -----------------------------------------------------------------------------

    --      CREATE display objects and add them to 'group' here.
    --      Example use-case: Restore 'group' from previously saved state.

    -----------------------------------------------------------------------------

end


-- Called BEFORE scene has moved onscreen:
function scene:willEnterScene( event )
       local group = self.view

     -----------------------------------------------------------------------------

     --      This event requires build 2012.782 or later.

     -----------------------------------------------------------------------------

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

         -----------------------------------------------------------------------------

         --      INSERT code here (e.g. stop timers, remove listeners, unload     sounds,etc.)

-----------------------------------------------------------------------------

 end


-- Called AFTER scene has finished moving offscreen:
function scene:didExitScene( event )
        local group = self.view

    -----------------------------------------------------------------------------

    --      This event requires build 2012.782 or later.

    -----------------------------------------------------------------------------

 end


 -- Called prior to the removal of scene's "view" (display group)
  function scene:destroyScene( event )
         local group = self.view

         -----------------------------------------------------------------------------

         --      INSERT code here (e.g. remove listeners, widgets, save state, etc.)

         -----------------------------------------------------------------------------

 end


-- Called if/when overlay scene is displayed via storyboard.showOverlay()
 function scene:overlayBegan( event )
         local group = self.view
         local overlay_name = event.sceneName  -- name of the overlay scene

         -----------------------------------------------------------------------------

         --      This event requires build 2012.797 or later.

         -----------------------------------------------------------------------------

 end


 -- Called if/when overlay scene is hidden/removed via storyboard.hideOverlay()
  function scene:overlayEnded( event )
         local group = self.view
         local overlay_name = event.sceneName  -- name of the overlay scene

         -----------------------------------------------------------------------------

         --      This event requires build 2012.797 or later.

         -----------------------------------------------------------------------------

 end



  ---------------------------------------------------------------------------------
  -- END OF YOUR IMPLEMENTATION
  ---------------------------------------------------------------------------------

 -- "createScene" event is dispatched if scene's view does not exist
  scene:addEventListener( "createScene", scene )

  -- "willEnterScene" event is dispatched before scene transition begins
  scene:addEventListener( "willEnterScene", scene )

 -- "enterScene" event is dispatched whenever scene transition has finished
  scene:addEventListener( "enterScene", scene )

  -- "exitScene" event is dispatched before next scene's transition begins
  scene:addEventListener( "exitScene", scene )

  -- "didExitScene" event is dispatched after scene has finished transitioning out
  scene:addEventListener( "didExitScene", 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 )

 -- "overlayBegan" event is dispatched when an overlay scene is shown
 scene:addEventListener( "overlayBegan", scene )

 -- "overlayEnded" event is dispatched when an overlay scene is hidden/removed
 scene:addEventListener( "overlayEnded", scene )

  ---------------------------------------------------------------------------------

  return scene

You could also try a popular third party scene manager called Director class. It is not built into Corona, but is a little simpler to learn.

http://developer.coronalabs.com/code/director-class-10

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top