我看不到任何按钮或背景(Corona SDK)

时间:2013-05-05 21:17:10

标签: lua storyboard corona

我正在尝试为Android Google Play商店制作游戏。但是,当我制作主菜单时,我遇到了一个问题。

在我添加故事板和场景功能之前,一切正常。但是现在我跑步时看不到任何东西。

另外,我没有错误。

    -- 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

2 个答案:

答案 0 :(得分:1)

试试这个:

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

答案 1 :(得分:0)

我认为你应该在插入所有对象后插入背景,或者你也可以在screenGroup上添加你添加的背景上的所有对象。可能是背景图像隐藏了所有对象。 尝试以上解决方案,如果它不会帮助你。使用我的解决方案后,请让我知道究竟是什么问题。 祝你好运!