Cole Thrailkill
Cole Thrailkill

Reputation: 31

I can't see any of the buttons, or the background (Corona SDK)

I'm trying to make a game for the Android Google Play store. But, when I was making the main menu I ran into an issue.

Before I added the storyboard and the scene functions, everything worked fine. But now I can't see a thing when I run it.

Also, I get no errors.

    -- Requires

    local widget = require "widget"

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

    function scene:createScene(event)

screenGroup = self.view

-- Background
local background = display.newImage("images/bg.png")
screenGroup:insert(background)

-- Title
local title = display.newImage("images/title.png")
title.x = display.contentCenterX
title.y = display.contentCenterY - 110
screenGroup:insert(title)

-- Play game
local button1 = widget.newButton {

    label = "Play Game",
    font = default,
    fontSize = 24,
    width = 200,
    height = 50

}
button1.x = display.contentCenterX
button1.y = display.contentCenterY - 47
screenGroup:insert(button1)

-- How To Play
local button2 = widget.newButton {

    label = "How To Play",
    font = default,
    fontSize = 24,
    width = 200,
    height = 50

}
button2.x = display.contentCenterX
button2.y = display.contentCenterY + 13
screenGroup:insert(button2)

-- Level Select
local button3 = widget.newButton {

    label = "Level Select",
    font = default,
    fontSize = 24,
    width = 200,
    height = 50

}
button3.x = display.contentCenterX
button3.y = display.contentCenterY + 73
screenGroup:insert(button3)

-- About Us
local button4 = widget.newButton {

    label = "About Us",
    font = default,
    fontSize = 24,
    width = 200,
    height = 50

}
button4.x = display.contentCenterX
button4.y = display.contentCenterY + 133
screenGroup:insert(button4)

    end

    function start(event)
if event.phase == "began" then
    storyboard.gotoScene("level1", "fade", 400)
end
    end

    function scene:enterScene(event)
button1:addEventListener("touch", start)
    end

    return scene

Upvotes: 0

Views: 419

Answers (2)

vovahost
vovahost

Reputation: 36007

Try this:

main.lua

local storyboard = require "storyboard"
storyboard.gotoScene( "scene1")

scene1.lua

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

function scene:createScene( event )
    local screenGroup = self.view

    -- Background
    local background = display.newImage("images/bg.png")
    screenGroup:insert(background)

    -- Title
    local title = display.newImage("images/title.png")
    title.x = display.contentCenterX
    title.y = display.contentCenterY - 110
    screenGroup:insert(title)

    -- Play game
    local button1 = widget.newButton {

        label = "Play Game",
        font = default,
        fontSize = 24,
        width = 200,
        height = 50

    }
    button1.x = display.contentCenterX
    button1.y = display.contentCenterY - 47
    screenGroup:insert(button1)

    -- How To Play
    local button2 = widget.newButton {

        label = "How To Play",
        font = default,
        fontSize = 24,
        width = 200,
        height = 50

    }
    button2.x = display.contentCenterX
    button2.y = display.contentCenterY + 13
    screenGroup:insert(button2)

    -- Level Select
    local button3 = widget.newButton {

        label = "Level Select",
        font = default,
        fontSize = 24,
        width = 200,
        height = 50

    }
    button3.x = display.contentCenterX
    button3.y = display.contentCenterY + 73
    screenGroup:insert(button3)

    -- About Us
    local button4 = widget.newButton {

        label = "About Us",
        font = default,
        fontSize = 24,
        width = 200,
        height = 50

    }
    button4.x = display.contentCenterX
    button4.y = display.contentCenterY + 133
    screenGroup:insert(button4)

end

function start(event)
    if event.phase == "began" then
        storyboard.gotoScene("level1", "fade", 400)
    end
end

function scene:enterScene(event)
    button1:addEventListener("touch", start)
end

scene:addEventListener( "createScene", scene )
scene:addEventListener( "enterScene", scene )

return scene

Upvotes: 1

Varsha
Varsha

Reputation: 558

I think you should insert background after inserting all the objects or you can also insert all the objects on the background which you have added on the screenGroup. May be background image is hiding all the objects. Try above solution, if it will not help you. Please let me know what exactly is the problem after using my solution. Good luck!

Upvotes: 0

Related Questions