Understanding Scenes in the Corona SDK

I am very new to Corona.

In my game, I would like to have a menu with several options (for example, "single player" or "settings"). When you tap any of these options, the screen disappears and a new one appears.

This next screen (for example, by clicking "single player") should have some text, for example, "Choose your character", and as soon as the user touches his character, another screen will disappear, etc.

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

Please do not hesitate to explain, or too much, post a link to a clear source, for example, another question or video from YouTube.

One more thing: is it possible for the user to skip the screen, which will trigger an event that will return him / her back to another screen / scene?

+4
source share
4 answers

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

And yes, you can use the swipe event to trigger pagination. To do this, ask this question: How to promote pages in the Corona SDK

+2
source

The current scene manager supporting the crown, composer (the storyboard is outdated and will not be available in the future)

Scenes in the crown are managed and processed by composer

Here is a link to a composer tutorial

Each scene has the following events to which it responds:

  • create
  • show
  • hide
  • destroy

The key to understanding the life cycle of a scene is to remember that the create event gets only once until the scene is destroyed.

The show event is show every time a scene is displayed.

The hide event is called eveytime when the scene is rejected.

The destroy event is raised only when the OS decides to get rid of this scene memory. This may not happen until you exit your application.

+2
source

Yes, this whole plan can be done using scenes for an organized game.

For each scene, you can follow this recommended format at the end of this page . I will dial it here at the end of this answer.

When you have scenes, you call them with:

 storyboard.gotoScene("name_Of_The_Scene") 

and erase the scene

 storyboard.purgeScene("name_Of_The_Scene") 

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

Recommended format for the scene

(for copy and paste)

 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 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 (eg 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 (eg 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 "view" (display group) function scene:destroyScene( event ) local group = self.view ----------------------------------------------------------------------------- -- INSERT code here (eg 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 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 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 
+1
source

You can also try a popular third-party scene manager called Director Class. It is not built into the Crown, but is a little easier to learn.

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

0
source

Source: https://habr.com/ru/post/1487544/


All Articles