user3809806
user3809806

Reputation:

black screen while running corona sdk(i am using composer)

So once i save it and click launch the screen is black no scenes are showing

can someone figure out what is wrong with this and know how to correctly fix it. I'll be gladly if someone can.

Thank You.

This is my Main.lua-

display.setStatusBar(display.HiddenStatusBar)

local composer = require( "composer" )
local scene = composer.newScene()

-- your code goes here...

composer.gotoScene("menu")

THIS is my Menu.lua-

display.setStatusBar(display.HiddenStatusBar)

local composer = require( "composer" )

local scene = composer.newScene()

-- -----------------------------------------------------------------------------------------------------------------
-- All code outside of the listener functions will only be executed ONCE unless "composer.removeScene()" is called.
-- -----------------------------------------------------------------------------------------------------------------

-- local forward references should go here

-- -------------------------------------------------------------------------------


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

   local background = display.newImageRect( "background.png", 730, 400 )
   sceneGroup:insert( background )

end


-- "scene:show()"
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.
        print("menu")
    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.
end


-- -------------------------------------------------------------------------------

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

-- -------------------------------------------------------------------------------

return scene

Upvotes: 0

Views: 725

Answers (2)

Kumar KS
Kumar KS

Reputation: 521

I think the possible problem could be the path of the image and the scene.

If your are using the above code then all your background image and menu.lua should be in the main folder and not in any sub folder first check these two things.

Then i think your not giving the x and y values of the image,

background .x = display.contentWidth/2 background .y = display.contentHeight/2

These are possible problems.

Upvotes: 1

Koormo
Koormo

Reputation: 166

Try this at the beginning of your menu.lua

display.setStatusBar(display.HiddenStatusBar)

local composer = require( "composer" )

local scene = composer.newScene()
local background
-- -----------------------------------------------------------------------------------------------------------------
-- All code outside of the listener functions will only be executed ONCE unless "composer.removeScene()" is called.
-- -----------------------------------------------------------------------------------------------------------------

-- local forward references should go here

-- -------------------------------------------------------------------------------


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

   background = display.newImageRect( "background.png", 730, 400 )
   background.x = display.contentCenterX
   background.y = display.contentCenterY
   sceneGroup:insert( background )

end 

You need to declare the background image as local in your scene file (menu.lua), not local in your create function

Upvotes: 0

Related Questions