2012-12-27 37 views
0

我在使用Corona SDK时有点新,而且我的主菜单按钮有点问题。每当我按下按钮时,它都不会移动或改变视图;这些按钮就会在标题屏幕中消失。主菜单的Corona SDK UI按钮

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 

回答

2

首先我看到你声明本地ui两次。

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

0

也正因:导演:changeScene(“新游戏”)

这将尝试去场景中,您正在放置场景文件的名称。在同一文件夹中的文件main.lua

新Game.lua

:在这种情况下,它在寻找一个名为文件。我个人会避免在其中包含空格的文件名,而模拟器不区分大小写,而设备是,并且您必须确保文件名大小写符合您所编码的内容。

此外,我很担心这条线:导演:changeScene(“titleScreen”)

它会努力改变场景之前,你永远能设置你的按钮。

0

改变这一行

local ui = require ("director") 

local director = require ("director") 

和是确保文件名是正确的。