Objects not showing in function scene:show( event )

I can’t seem to figure out what I am doing wrong. If the objects are outside the

function scene:create( event )

 local sceneGroup = self.view

end

They seem to show but when I put them inside it nothing shows just a black screen.

Any help would be appreciated! 

Did you make sure to add the scene listeners at the end of your file?

--------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

Are there any errors in your terminal/command window?  If you have an error in your scene:create() it could black screen you.  Post some code for us to look at?

Rob

Here is what I have guys.

----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- local composer = require( "composer" ) local scene = composer.newScene() -- include Corona's "widget" library local widget = require "widget" -------------------------------------------- -- forward declarations and other locals local playBtn -- 'onRelease' event listener for playBtn local function onPlayBtnRelease() -- go to levelSelect.lua scene composer.gotoScene( "levelSelect", "fade", 500 ) return true -- indicates successful touch end function scene:create( event ) local sceneGroup = self.view -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. -- Background local sky = display.newImage ("startScreen/sky.png") sky.x = display.contentWidth/2; sky.y = display.contentHeight/2; -- Picture local preston = display.newImage ("startScreen/PrestonArt.png") preston:scale( 0.4, 0.4 ) preston.x = display.contentWidth/2; preston.y = display.contentHeight/2; -- Labels local learningLabel = display.newImage ("startScreen/Learning.png") learningLabel:scale( 0.3, 0.3 ) learningLabel.x = 506; learningLabel.y = 170; local centerLabel = display.newImage ("startScreen/Center.png") centerLabel:scale( 0.3, 0.3 ) centerLabel.x = 506; centerLabel.y = 600; -- create a widget button (which will loads levelSelect.lua on release) playBtn = widget.newButton{ defaultFile = "startScreen/Play.png", --the "default" image file overFile = "startScreen/Play-Over.png", --the "over" image file width=240, height=120, onRelease = onPlayBtnRelease -- event listener function } playBtn.x = 300; playBtn.y = 695; -- all display objects must be inserted into group sceneGroup:insert( sky ) sceneGroup:insert( preston ) sceneGroup:insert( playBtn ) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. if playBtn then playBtn:removeSelf() -- widgets must be manually removed playBtn = nil end end -- ------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ------------------------------------------------------------------------------- return scene

No errors that I can see Rob

Is that really your main.lua?  If so, main.lua is almost never a “scene”.  Its an overall app initialization point and a jump off into Composer to manage the scene.

If that is your main.lua, rename it to something like “scene1.lua” and create a new main.lua that contains:

local composer = require( “composer” )

– other init code here, like ads, gamenetworking, iap, facebook etc.

compser.gotoScene(“scene1”)

You also need to insert your learningLabel and such (any display object you create in scene:create()  ) into the sceneGroup.

Rob

Thanks Rob I created the proper files and added  items to the group. I now get this error on the main.lua sheet

Attempt to index global ‘compser’ (a nil value)

If the error you pasted is not a typo, then “comp o ser” is misspelled.

Im such a noob didnt even catch that thanks

No worries. Happens to everyone!

So I got everything working I have the main.lua going to mainScreen.lua  but now when I push the button to go to the next scene it gives me this message:

File: ?

Attempt to concatenate global ‘sceneName’ (a nil value)

stack traceback:

?: in function ‘gotoScene’

mainScreen.lua:27: in function ‘_onRelease’

?: in function ‘?’

?: in function <?:677>

?: in function <?:221>

 

 

I have the next scene within the project and I the thing I can think of is the function listed above. Any Ideas

Does your levelSelect.lua scene exist?  Is it doing a “return scene” as it’s last line?

Rob

Hey Rob Yes the file exist and i realize early it didnt have the return scene and added it and it worked thanks

Did you make sure to add the scene listeners at the end of your file?

--------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

Are there any errors in your terminal/command window?  If you have an error in your scene:create() it could black screen you.  Post some code for us to look at?

Rob

Here is what I have guys.

----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- local composer = require( "composer" ) local scene = composer.newScene() -- include Corona's "widget" library local widget = require "widget" -------------------------------------------- -- forward declarations and other locals local playBtn -- 'onRelease' event listener for playBtn local function onPlayBtnRelease() -- go to levelSelect.lua scene composer.gotoScene( "levelSelect", "fade", 500 ) return true -- indicates successful touch end function scene:create( event ) local sceneGroup = self.view -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. -- Background local sky = display.newImage ("startScreen/sky.png") sky.x = display.contentWidth/2; sky.y = display.contentHeight/2; -- Picture local preston = display.newImage ("startScreen/PrestonArt.png") preston:scale( 0.4, 0.4 ) preston.x = display.contentWidth/2; preston.y = display.contentHeight/2; -- Labels local learningLabel = display.newImage ("startScreen/Learning.png") learningLabel:scale( 0.3, 0.3 ) learningLabel.x = 506; learningLabel.y = 170; local centerLabel = display.newImage ("startScreen/Center.png") centerLabel:scale( 0.3, 0.3 ) centerLabel.x = 506; centerLabel.y = 600; -- create a widget button (which will loads levelSelect.lua on release) playBtn = widget.newButton{ defaultFile = "startScreen/Play.png", --the "default" image file overFile = "startScreen/Play-Over.png", --the "over" image file width=240, height=120, onRelease = onPlayBtnRelease -- event listener function } playBtn.x = 300; playBtn.y = 695; -- all display objects must be inserted into group sceneGroup:insert( sky ) sceneGroup:insert( preston ) sceneGroup:insert( playBtn ) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. if playBtn then playBtn:removeSelf() -- widgets must be manually removed playBtn = nil end end -- ------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ------------------------------------------------------------------------------- return scene

No errors that I can see Rob

Is that really your main.lua?  If so, main.lua is almost never a “scene”.  Its an overall app initialization point and a jump off into Composer to manage the scene.

If that is your main.lua, rename it to something like “scene1.lua” and create a new main.lua that contains:

local composer = require( “composer” )

– other init code here, like ads, gamenetworking, iap, facebook etc.

compser.gotoScene(“scene1”)

You also need to insert your learningLabel and such (any display object you create in scene:create()  ) into the sceneGroup.

Rob