Show display object

Hi,

I am having a problem with showing display objects.
In my project I am opening an overlay and I wanted to show a screenshot of the game in the background.

Therefore I am making the screenshot and transfer it to the overlay.

In the overlay, I have got the display object but it is not visible.
I can read the position and anything else. But I can’t see it.

My code looks as follows:

game.lua

local function gotoOptions() -- Capture the screen local screenCap = display.captureScreen( true ) composer.showOverlay( 'options', { isModal = true, effect = 'fade', time = 500, params = { screen = screenCap }}) screenCap:removeSelf() end

Options.lua

function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then screen = event.params.screen bg:insert ( screen ) end end

Thank you :slight_smile:

Try

sceneGroup:insert( screen )

instead of : “bg:…” in options.lua

greetz

Thank you for your reply,

Unfortunately that didn’t help.

I still can’t see the screenshot.
Strangely it acts as if it was visible, but I can’t see it.

What surprised me a bit is, that the overlay has a white background by default. I expected it to be black.

I hope, someone has a suggestion

Christian
 

If the overlay has been created without any content it is fully transparent. To have any visible color (object) you must have set up these anywhere in your code. So, the given snippets aren’t your real code?

Delete

screenCap:removeSelf()

from function and move to scene:hide(), or your screenshot gets deleted right before the overlay comes to screen.

Following is the modified code of the sample “Composer” from Corona SDK examples. Copy the folder Composer to a new place and add/replace the attached files or check the code below to get an idea of it.

[spoiler]

overlay.lua

local composer = require( "composer" ) local scene = composer.newScene() local res, screenCap function scene:create( event ) local sceneGroup = self.view screenCap = event.params.sampleVar sceneGroup:insert( screenCap ) end print( "\n1: create event") function scene:show( event ) local phase = event.phase if "did" == phase then print( "overlay: show event, phase did" ) --local image = display.newImage() end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase local parent = event.parent -- Reference to the parent scene object if ( phase == "will" ) then screenCap:removeSelf() end end local function res(event) if event.numTap==1 then print("tapped") -- By some method such as a "resume" button, hide the overlay composer.hideOverlay( "fade", 1000 ) end end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) Runtime:addEventListener("tap", res) scene:addEventListener( "hide", scene ) return scene

[/spoiler][spoiler]

scene1.lua

--------------------------------------------------------------------------------- -- -- scene1.lua -- --------------------------------------------------------------------------------- local composer = require( "composer" ) local scene = composer.newScene() --------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- local image, text1, text2, text3, memTimer -- Touch event listener for background image local function onSceneTouch( self, event ) if event.phase == "began" then composer.gotoScene( "scene2", "slideLeft", 800 ) return true end end -- Called when the scene's view does not exist: function scene:create( event ) local sceneGroup = self.view image = display.newImage( "bg.jpg" ) image.x = display.contentCenterX image.y = display.contentCenterY sceneGroup:insert( image ) image.touch = onSceneTouch text1 = display.newText( "Scene 1", 0, 0, native.systemFontBold, 24 ) text1:setFillColor( 255 ) text1.x, text1.y = display.contentWidth \* 0.5, 50 sceneGroup:insert( text1 ) text2 = display.newText( "MemUsage: ", 0, 0, native.systemFont, 16 ) text2:setFillColor( 255 ) text2.x, text2.y = display.contentWidth \* 0.5, display.contentHeight \* 0.5 sceneGroup:insert( text2 ) text3 = display.newText( "Touch to continue.", 0, 0, native.systemFontBold, 18 ) text3:setFillColor( 255 ); text3.isVisible = false text3.x, text3.y = display.contentWidth \* 0.5, display.contentHeight - 100 sceneGroup:insert( text3 ) print( "\n1: create event") end function scene:show( event ) local phase = event.phase if "did" == phase then print( "1: show event, phase did" ) -- remove previous scene's view composer.removeScene( "scene4" ) local screenCap = display.captureScreen( ) screenCap.rotation=180 screenCap:setFillColor(1,1,0,0.8) -- tint the screenshot yellow screenCap.x = display.contentCenterX screenCap.y = display.contentCenterY local optionsT = { isModal = false, effect = "fade", time = 1000, params = { sampleVar = screenCap } } composer.showOverlay( "overlay", optionsT ) -- Update Lua memory text display local showMem = function() image:addEventListener( "touch", image ) text3.isVisible = true text2.text = text2.text .. string.format("%.2g", collectgarbage("count")/1000) .. "MB" text2.x = display.contentWidth \* 0.5 end memTimer = timer.performWithDelay( 1000, showMem, 1 ) end end function scene:hide( event ) local phase = event.phase if "will" == phase then print( "1: hide event, phase will" ) -- remove touch listener for image image:removeEventListener( "touch", image ) -- cancel timer timer.cancel( memTimer ); memTimer = nil; -- reset label text text2.text = "MemUsage: " end end function scene:destroy( event ) print( "((destroying scene 1's view))" ) end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

[/spoiler]

Thanks for your replies, they helped very much.

I’ve had two problems:
There was a scrollview, that made the background white. Therefore it was not transparent.
Now i deleted the scrollview and work without it. I have a transparent background now.

And I thought, when I transfer the screnncapture as a parameter, I could delete the original. That was wrong.
Now I keep the original and handle it with a gaussianBlur like I wanted.
A simple :toBack() sent the image, where it should be.

Thank you all.

Christian

Try

sceneGroup:insert( screen )

instead of : “bg:…” in options.lua

greetz

Thank you for your reply,

Unfortunately that didn’t help.

I still can’t see the screenshot.
Strangely it acts as if it was visible, but I can’t see it.

What surprised me a bit is, that the overlay has a white background by default. I expected it to be black.

I hope, someone has a suggestion

Christian
 

If the overlay has been created without any content it is fully transparent. To have any visible color (object) you must have set up these anywhere in your code. So, the given snippets aren’t your real code?

Delete

screenCap:removeSelf()

from function and move to scene:hide(), or your screenshot gets deleted right before the overlay comes to screen.

Following is the modified code of the sample “Composer” from Corona SDK examples. Copy the folder Composer to a new place and add/replace the attached files or check the code below to get an idea of it.

[spoiler]

overlay.lua

local composer = require( "composer" ) local scene = composer.newScene() local res, screenCap function scene:create( event ) local sceneGroup = self.view screenCap = event.params.sampleVar sceneGroup:insert( screenCap ) end print( "\n1: create event") function scene:show( event ) local phase = event.phase if "did" == phase then print( "overlay: show event, phase did" ) --local image = display.newImage() end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase local parent = event.parent -- Reference to the parent scene object if ( phase == "will" ) then screenCap:removeSelf() end end local function res(event) if event.numTap==1 then print("tapped") -- By some method such as a "resume" button, hide the overlay composer.hideOverlay( "fade", 1000 ) end end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) Runtime:addEventListener("tap", res) scene:addEventListener( "hide", scene ) return scene

[/spoiler][spoiler]

scene1.lua

--------------------------------------------------------------------------------- -- -- scene1.lua -- --------------------------------------------------------------------------------- local composer = require( "composer" ) local scene = composer.newScene() --------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- local image, text1, text2, text3, memTimer -- Touch event listener for background image local function onSceneTouch( self, event ) if event.phase == "began" then composer.gotoScene( "scene2", "slideLeft", 800 ) return true end end -- Called when the scene's view does not exist: function scene:create( event ) local sceneGroup = self.view image = display.newImage( "bg.jpg" ) image.x = display.contentCenterX image.y = display.contentCenterY sceneGroup:insert( image ) image.touch = onSceneTouch text1 = display.newText( "Scene 1", 0, 0, native.systemFontBold, 24 ) text1:setFillColor( 255 ) text1.x, text1.y = display.contentWidth \* 0.5, 50 sceneGroup:insert( text1 ) text2 = display.newText( "MemUsage: ", 0, 0, native.systemFont, 16 ) text2:setFillColor( 255 ) text2.x, text2.y = display.contentWidth \* 0.5, display.contentHeight \* 0.5 sceneGroup:insert( text2 ) text3 = display.newText( "Touch to continue.", 0, 0, native.systemFontBold, 18 ) text3:setFillColor( 255 ); text3.isVisible = false text3.x, text3.y = display.contentWidth \* 0.5, display.contentHeight - 100 sceneGroup:insert( text3 ) print( "\n1: create event") end function scene:show( event ) local phase = event.phase if "did" == phase then print( "1: show event, phase did" ) -- remove previous scene's view composer.removeScene( "scene4" ) local screenCap = display.captureScreen( ) screenCap.rotation=180 screenCap:setFillColor(1,1,0,0.8) -- tint the screenshot yellow screenCap.x = display.contentCenterX screenCap.y = display.contentCenterY local optionsT = { isModal = false, effect = "fade", time = 1000, params = { sampleVar = screenCap } } composer.showOverlay( "overlay", optionsT ) -- Update Lua memory text display local showMem = function() image:addEventListener( "touch", image ) text3.isVisible = true text2.text = text2.text .. string.format("%.2g", collectgarbage("count")/1000) .. "MB" text2.x = display.contentWidth \* 0.5 end memTimer = timer.performWithDelay( 1000, showMem, 1 ) end end function scene:hide( event ) local phase = event.phase if "will" == phase then print( "1: hide event, phase will" ) -- remove touch listener for image image:removeEventListener( "touch", image ) -- cancel timer timer.cancel( memTimer ); memTimer = nil; -- reset label text text2.text = "MemUsage: " end end function scene:destroy( event ) print( "((destroying scene 1's view))" ) end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

[/spoiler]

Thanks for your replies, they helped very much.

I’ve had two problems:
There was a scrollview, that made the background white. Therefore it was not transparent.
Now i deleted the scrollview and work without it. I have a transparent background now.

And I thought, when I transfer the screnncapture as a parameter, I could delete the original. That was wrong.
Now I keep the original and handle it with a gaussianBlur like I wanted.
A simple :toBack() sent the image, where it should be.

Thank you all.

Christian