主菜单的Corona SDK Ui按钮

时间:2012-12-27 07:01:24

标签: lua corona

我是使用Corona SDK的新手,我在主菜单按钮上遇到了一些问题。每当我按下按钮时,它都不会移动或改变视图;按钮刚刚在标题画面中消失。

module(..., package.seeall)

local ui = require ("ui")
local ui = require ("director")

local assetPath = "assets/"

local mainGroup = display.newGroup()

function new(params)
    local titleScreen = display.newImageRect(assetPath .. "Law of Magic.jpg", 
        display.contentWidth, display.contentHeight)
    titleScreen.x = display.contentWidth / 2
    titleScreen.y = 265
    mainGroup:insert(titleScreen)
    director:changeScene("titleScreen")

    local newgame = ui.newButton{ default = assetPath .. "new game.png", 
        onRelease = function(event)  director:changeScene("New game") end,}
    newgame.x = display.contentWidth / 2
    newgame.y = 445
    mainGroup:insert(newgame)

    local continue = ui.newButton{ default = assetPath .. "continue.png", 
        onRelease = function(event)  director:changeScene("Continue") end,}
    continue.x = display.contentWidth / 2
    continue.y = 447
    mainGroup:insert(continue)

    local option = ui.newButton{ default = assetPath .. "option.png", 
        onRelease = function(event)  director:changeScene("Option") end,}
    option.x = display.contentWidth / 2
    option.y = 449
    mainGroup:insert(option)

    local help = ui.newButton{ default = assetPath .. "help.png", 
        onRelease = function(event)  director:changeScene("Help") end,}
    help.x = display.contentWidth / 2
    help.y = 451
    mainGroup:insert(help)

    local exitgame = ui.newButton{ default = assetPath .. "exit game.png", 
        onRelease = function(event)  director:changeScene("Exit game") end,}
    exitgame.x = display.contentWidth / 2
    exitgame.y = 453
    mainGroup:insert(exitgame)

    return mainGroup
end

3 个答案:

答案 0 :(得分:2)

首先,我看到你宣布当地的ui两次。

其次你应该使用故事板,因为它是由电晕支持的,你是coronaSDk的新手

答案 1 :(得分:0)

也是这样的:导演:changeScene(“新游戏”)

它将尝试去一个场景,你正在放置场景文件的名称。在这种情况下,它正在寻找一个名为:

的文件

New Game.lua

与main.lua文件位于同一文件夹中。我个人会避免使用带有空格的文件名,虽然模拟器不区分大小写,但设备是,你必须确保文件名大小写匹配你编码的内容。

我也很担心这一行:导演:changeScene(“titleScreen”)

在设置按钮之前,它会尝试更改场景。

答案 2 :(得分:0)

更改此行

local ui = require ("director")

local director = require ("director")

是的,确保文件名正确无误。