Corona SDK主菜单的Ui按钮

我在使用 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
点赞
用户1937554
用户1937554

将下面翻译成中文并且保留原本的 markdown 格式

首先,我看到您声明了两次本地 UI。

其次,您应该使用 storyboard,因为它被 Corona 支持,而且您还是 Corona SDK 的新手。

2012-12-30 06:36:16
用户1870706
用户1870706

对于这条指令:director:changeScene("New game")

它会尝试进入一个场景,你需要输入场景文件的名称。在这种情况下,它会寻找一个叫做:

New Game.lua

的文件,它与你的 main.lua 文件在同一个文件夹中。我个人建议避免在文件名中使用空格,虽然模拟器不区分大小写,但是设备是区分大小写的,你必须确保文件名与你的代码匹配。

同时,我也对这一行存在顾虑:director:changeScene("titleScreen")

这会在你设置按钮之前尝试切换场景。

2013-01-06 03:14:13
用户2902517
用户2902517

将这一行修改为:

local director = require ("director")

并且确保文件名是正确的。

2016-03-08 23:18:05