CORONASDK Scene Management gallery: Composer library (bottom)

Source: Internet
Author: User

1 Overlay Scenarios

Composer allows you to have a overlay scenario. ( at any moment, only one overlay scene is displayed ) This is a special scenario that can be loaded and then overwritten on top of the active scene (the parent scene). The structure of a cladding scene is not the same as other composer scenes.

1.1 Displaying a overlay scene

In order to display a overlay scenario, the function composer.showoverlay () needs to be called. Because a cladding scenario generally does not cover the entire scene, the user may interact with the parent scene at the bottom. If you want to prevent users from interacting with the parent scene, you can set the Ismodal parameter in option to TRUE. Doing so prevents the Touch/tap event from reaching the parent scene through the overlay scene.

local options = {    "fade",         true"inventory", Options)

When the overlay scene is loaded, he needs to deal with his events as well as other scenes. That is, scene:create (), Scene:show (), Scene:hide (), and Scene:destroy () will invoke the same rules as other scenarios.

1.2 Hiding a overlay scene

To hide a cladding scene and return to the parent scene, you can use the Composer.hideoverlay () call, for example:

" Frombottom "  )

This call can come from the overlay scenario, from the parent scene, or from other event handlers, such as the "Back" key for Android. When you jump to another scene through Composer.gotoscene (), the overlay scene is automatically hidden.

Summary:

Overlay scenes appear to be suitable for making pop-ups in the game, whether it's a partial popup or a full-screen window. Can be recalled at any time in other scenes, or can be hidden at any time. Combined with different transition effects, it should be a good choice to make a game pop-up with overlay scenes.

Similar to some app's bottom resident navigation buttons, it doesn't seem appropriate to use overlay scenarios, because overlay scenes are automatically hidden when switching scenes using Gotoscene. Those features may be more suitable for displayobject out of the scene.

1.3 Accessing the parent scene

When you show or hide a overlay scene, you may need to do some action on the parent scene. For example, you might need to get some input or selection from the phone in the overlay scene, and then update the data into the parent scene. In composer, the overlay scene can access the parent scene object through Event.parent. This allows you to access the properties and methods of the parent scene and communicate with the parent scene object when the overlay scene is displayed or hidden. For example:

--------------------------------------------------------------------------------In "Scene1.lua" (Parent scene)------------------------------------------------------------------------------LocalComposer =require("composer" )LocalScene =Composer.newscene ()--Custom function for resuming the game (from pause State)functionScene:resumegame ()--code to resume gameEnd--Options table for the overlay scene "Pause.lua"LocalOptions ={Ismodal=true, Effect="Fade", time= -, params={Samplevar="My sample variable"    }}--by some method (a pause button, for example), show the overlayComposer.showoverlay ("Pause", Options)returnScene--------------------------------------------------------------------------------In "Pause.lua"------------------------------------------------------------------------------LocalComposer =require("composer" )LocalScene =Composer.newscene ()functionscene:hide (Event)LocalScenegroup =Self.viewLocalPhase =Event.phaseLocalParent = Event.parent--reference to the parent scene object    if(Phase = =" would") Then        --Call the ' resumegame () ' function in the parent sceneParent:resumegame ()EndEnd--by some method (a "Resume" button, for example), hide the overlayComposer.hideoverlay ("Fade", -) Scene:addeventlistener ("Hide", Scene)returnScene

2 Other methods/properties

Composer provides a number of convenient methods and properties to assist you with scene management.

2.1 Set/get Variable

You can store global name-value pairs of variables into the composer module, which can be accessed between scenes. In order to set a variable that may be accessed by another composer scene, you can use the composer.setvariable () function, for example:

" Gamelevel " 1  "playername" "zorron ")

Then, in order to get this variable from another scenario:

Local " PlayerName " )

2.2 Get a scene name

To get a scene name, you can use the Composer.getscenename () function to pass it a string with the value of one of the following:

    • "Current": Get the name of the present scene
    • "Previous": Get a scene name that was previously displayed
    • "Overlay": Gets the name of the overlay scene (if it is in the display)
Local "  Current " )Local "previous"  )local"  Overlay" )

3 Composer Stage Object

The Composer.stage property returns a reference to the top-level composer display Group, where all scene view objects are inserted. You can understand it as "compose scene layer", which is useful when you need to place a display object above or below all composer scenes, even during animation effects. For example:

    • A background image that is displayed below all composer scenes, always stationary, even during scene transitions
    • A tab or UI bar that always appears at the top of all composer scenes
    • The elements of the HUD (top level display), such as the amount of blood, fractions, etc.

As an example:

Composer.stage:toBack () Composer.stage:toFront ()

4 Scene debugging

The Composer.isdebug property can toggle "Composer debug Mode", and if set to true, useful debugging information is typically printed in the Corona Emulator console. You should set the setting to False (the default) before you build the project for deployment.

CORONASDK Scene Management gallery: Composer library (bottom)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.