【问题标题】:Corona SDK Ui Button for Main Menu主菜单的 Corona SDK Ui 按钮
【发布时间】:2016-03-09 07:18:05
【问题描述】:

我在使用 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

【问题讨论】:

    标签: lua coronasdk


    【解决方案1】:

    首先我看到你两次声明本地用户界面。

    其次,您应该使用故事板,因为它受 corona 支持,并且您是 coronaSDk 的新手

    【讨论】:

      【解决方案2】:

      还有这个:director:changeScene("New game")

      它将尝试进入一个场景,您输入的是场景文件的名称。在这种情况下,它正在寻找一个名为:

      新游戏.lua

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

      我也关心这行:director:changeScene("titleScreen")

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

      【讨论】:

        【解决方案3】:

        改变这一行

        local ui = require ("director")
        

        local director = require ("director")
        

        是的,请确保文件名正确。

        【讨论】:

          猜你喜欢
          • 2018-06-08
          • 2018-04-10
          • 1970-01-01
          • 2016-12-07
          • 1970-01-01
          • 1970-01-01
          • 2019-01-08
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多