不能用Corona SDK“搞砸”

时间:2014-06-23 15:46:06

标签: lua corona

我尝试过,尝试过并尝试过。但是不能让它发挥作用。

所有我有它main.lua有一个按钮。然后我想要这个去约.lua。

我的主要是:

local function about(event)
    storyboard.gotoScene( "about", {"Fade", 500} )
    return true
end

local about = widget.newButton
    {
        top = 280,
        width = 320,
        height = 66,
        defaultFile = "about.png",
        overFile = "aboutdown.png",
        onRelease = about
}

我的about.lua是:

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


local background = display.newImage( "logo.png" )
background.x = display.contentCenterX
background.y = display.contentCenterY

请帮忙!

1 个答案:

答案 0 :(得分:1)

如果查看Storyboard API,您将看到用于创建场景的模板代码,将所有模板代码复制到about.lua并将您的实际代码包含在createScene函数中,它应该可以工作

第一步:使用模板代码创建一个新的about.lua。

第二步:在createScene函数中添加你的代码,backgroundwidget是前向声明,所以它们在函数调用之前

local widget = require ( "widget" )
local background

-- Called when the scene's view does not exist:
function scene:createScene( event )
    local group = self.view

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

    --      CREATE display objects and add them to 'group' here.
    --      Example use-case: Restore 'group' from previously saved state.

    -----------------------------------------------------------------------------
background = display.newImage( "logo.png" )
background.x = display.contentCenterX
background.y = display.contentCenterY
end