Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Overlay Scenes - test and questions
Started by OlinaChang Apr 25 2019 03:19 AM

4 replies to this topic
composer library showoverlay

Best Answer schizoid2k , 25 April 2019 - 04:27 AM

Olina,

 

Here's some suggestions to get you started...

 

1. The parameters you pass must be in a table called params.  You can add/remove/change keys/values within params.

 

2. I would create an invisible rectangle around the entire display and add an event listener that will close the pop-up window.

 

3. Grab the params values in your scene:show event, and display then via display.newText()

 

I hope this helps,

 

--john

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

OlinaChang

[GLOBAL: userInfoPane.html]
OlinaChang
  • Observer

  • 16 posts
  • Corona SDK

Hi all,

 

I learned Corona 2 years ago, and now I am trying to pick it back to modify/create my Apps. I reviewed Composer Library page, and feel I can understand better than 2 years ago. Therefore, I kinda try and error Overlay Scenes section and I got 3 questions. I am afraid pasting all code here makes the post too long, so I attach the files.

 

I made a scene1.lua as the parent scene, and pauseAA.lua as the overlay scene. I think it's like a dialog pop-up box. I set isModal = false on purpose to test ideas.

Here are 3 questions after I made this practice.

1). About pass and receive parameters between scenes:

In parent scene, I want to pass a table of parameter to child scene. Now the code is working correctly. However, in future, I might have more than one tables of data need to be passed over. Therefore, I named "params" in goPauseOptions a new name, paramsPassOver, and then receive it in child scene by using "local paramsGot = event.paramsPassOver". Of course, it's not working. I wonder what's wrong with my thought?
 

[[[Working Code block]]]

------------------------------------------------------------------------------
-- In "scene1.lua" (parent scene)
------------------------------------------------------------------------------

local function pause()
	
    local goPauseOptions = {    
        effect = "fade",
        time = 500,
        isModal = false,

        params = {                                  
            passedVar01 = "PASS sample variable",
            passedVar02 = 8888  
        }
    }
    composer.showOverlay( "pauseAA", goPauseOptions ) 
end

------------------------------------------------------------------------------
-- In "pauseAA.lua" (child scene)
------------------------------------------------------------------------------

function scene:create( event )
 
    local sceneGroup = self.view

    local paramsGot = event.params

    print( paramsGot.passedVar01)
    print( paramsGot.passedVar02)
 
end

[[[NOT Working Code block]]]

------------------------------------------------------------------------------
-- In "scene1.lua" (parent scene)
------------------------------------------------------------------------------
local function pause()
    
    local goPauseOptions = {    
        effect = "fade",
        time = 500,
        isModal = false,
        paramsPassOver = {                                  
            passedVar01 = "PASS sample variable",
            passedVar02 = 8888  
        }
    }
    composer.showOverlay( "pauseAA", goPauseOptions )
end
------------------------------------------------------------------------------
-- In "pauseAA.lua" (child scene)
------------------------------------------------------------------------------
function scene:create( event )
 
    local sceneGroup = self.view
    local paramsGot = event.paramsPassOver
    print( paramsGot.passedVar01)
    print( paramsGot.passedVar02)
 
end


2). What should I do to make the overlay goes back to parent scene by touching the outside of yellow box area? Like touching the outside of a pop-window to make it disappear?

For visual reference, here is the video that I record earlier before I made the tests of this post. It only show overlay scene and transitions.

In the code I attached here, I tried isModal = false, and made an extra button "Scene1" to receive the tap (it will print "Don't touch me" in Simulator Console). However, as Corona Documentation mentioned, isModal =true is only to prevent from potentially interacting with the parent scene underneath. How to make the child scene goes away by touching outside of it's area?

3). I wonder how to make the print result shows on scenes? For example, make the passed parameters 8888 appearing on pauseAA yellow box instead of showing on simulator console?

No matter who answer my questions. Thanks in advance!

Olina
 



[TOPIC: post.html]
#2

schizoid2k

[GLOBAL: userInfoPane.html]
schizoid2k
  • Contributor

  • 564 posts
  • Corona SDK

  Best Answer

Olina,

 

Here's some suggestions to get you started...

 

1. The parameters you pass must be in a table called params.  You can add/remove/change keys/values within params.

 

2. I would create an invisible rectangle around the entire display and add an event listener that will close the pop-up window.

 

3. Grab the params values in your scene:show event, and display then via display.newText()

 

I hope this helps,

 

--john


  • OlinaChang likes this

[TOPIC: post.html]
#3

OlinaChang

[GLOBAL: userInfoPane.html]
OlinaChang
  • Observer

  • 16 posts
  • Corona SDK

Hi John,

Thank you very much! I got your idea of the first 2 points.
Then I tried point 3 and it works well. I assigned paramsGot.passedVar02 to a variable,receivedText.

function scene:create( event )
 
    local sceneGroup = self.view
    -- Code here runs when the scene is first created but has not yet appeared on screen
   
    local paramsGot = event.params
    --print( paramsGot.passedVar01)
    --print( paramsGot.passedVar02)
    local receivedText = paramsGot.passedVar02
end

 

However, display.newText() in scene:show() can't get receivedText. Either I will have to make receivedText a global variable, or move

    local paramsGot = event.params
    local receivedText = paramsGot.passedVar02

into scene:show().

 

Either way is fine?

Should I avoid using Global Variable?

Here are the updated pauseAA.lua

local composer = require( "composer" )
 
local scene = composer.newScene()
 
-- -----------------------------------------------------------------------------------
-- Code outside of the scene event functions below will only be executed ONCE unless
-- the scene is removed entirely (not recycled) via "composer.removeScene()"
-- -----------------------------------------------------------------------------------
 
local function backToParent()
    composer.hideOverlay( "zoomInOutRotate", 1000 )
end
 
-- -----------------------------------------------------------------------------------
-- Scene event functions
-- -----------------------------------------------------------------------------------
 
-- create()
function scene:create( event )
 
    local sceneGroup = self.view
    -- Code here runs when the scene is first created but has not yet appeared on screen
    local paramsGot = event.params

    --print( paramsGot.passedVar01)
    --print( paramsGot.passedVar02)
    receivedText = paramsGot.passedVar02
end
 
 
-- show()
function scene:show( event )
 
    local sceneGroup = self.view
    local phase = event.phase
    
    if ( phase == "will" ) then
        -- Code here runs when the scene is still off screen (but is about to come on screen)
        
        local popWindow = display.newRect (display.contentCenterX, display.contentCenterY-50, 280 , 300)
        popWindow:setFillColor(1,1,0)
        sceneGroup:insert(popWindow)

        local myText = display.newText("RUSUME", display.contentCenterX, display.contentCenterY, native.systemFont, 46)
        myText:setFillColor( 0, 0.6, 0.2)
        sceneGroup:insert(myText)

        myText:addEventListener("tap", backToParent)

        local showText = display.newText( receivedText , display.contentCenterX, display.contentCenterY-70, native.systemFont, 30)
        showText:setFillColor(0, 0.3, 0.2)
        sceneGroup:insert(showText)

                        
    elseif ( phase == "did" ) then
        -- Code here runs when the scene is entirely on screen
 
    end
end
 
 
-- hide()
function scene:hide( event )
 
    local sceneGroup = self.view
    local phase = event.phase

    local parentAAA = event.parent 
    
    if ( phase == "will" ) then
        -- Code here runs when the scene is on screen (but is about to go off screen)
        
        parentAAA:resumeGame()
 
    elseif ( phase == "did" ) then
        -- Code here runs immediately after the scene goes entirely off screen
 
    end
end

 
-- destroy()
function scene:destroy( event )
 
    local sceneGroup = self.view
    -- Code here runs prior to the removal of scene's view
 
end
 
 
-- -----------------------------------------------------------------------------------
-- Scene event function listeners
-- -----------------------------------------------------------------------------------
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -----------------------------------------------------------------------------------
 
return scene

Thanks again!

--Olina



[TOPIC: post.html]
#4

OlinaChang

[GLOBAL: userInfoPane.html]
OlinaChang
  • Observer

  • 16 posts
  • Corona SDK

Oh, wait! My apology.

I just noticed you did say "Grab the params values in your scene:show event".

Amazing! Solved!

Thank you very very much!

--Olina



[TOPIC: post.html]
#5

schizoid2k

[GLOBAL: userInfoPane.html]
schizoid2k
  • Contributor

  • 564 posts
  • Corona SDK

Olina,

 

I'm glad everything is working!  :)


  • OlinaChang likes this


[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: composer library, showoverlay