无法在Lua中看到按钮。

我添加了一个logo和几个按钮,例如PLAY和CREDITS。我没有收到任何错误,并且很难看到问题,我错过了什么?

--设置背景
local bg = display.newImage("background.png")
--设置按钮
local title
local playBtn
local creditsBtn

--设置函数
local Main=('')
local startButtonListeners=('')

--开始设置函数
function Main()
title= display.newImage("logo.png")
playBtn= display.newImage("playbtn.png", 130, 248)
creditsBtn= display.newImage("creditsbtn.png", 125, 316)
titleView= display.newGroup(title, playBtn, creditsBtn)

startButtonListeners("add")
end
点赞
用户2291928
用户2291928

如果这就是你的全部代码,那么你从未调用过主函数。在corona中,你不需要调用主函数,main.lua会在项目开始时运行。所以尝试像这样运行你的代码:

--Background
local bg = display.newImage("background.png")
--Buttons
local title
local playBtn
local creditsBtn

--Functions
local Main
local startButtonListeners, anotherButtonListener

--Start of Functions
Main = function()
   title= display.newImage("logo.png")
   playBtn= display.newImage("playbtn.png", 130, 248)
   creditsBtn= display.newImage("creditsbtn.png", 125, 316)
   titleView= display.newGroup()
   titleView:insert(title)
   titleView:insert(playBtn)
   titleView:insert(creditsBtn)

   playBtn:addEventListener("tap", startButtonListeners)
   --creditsBtn:addEventListener("tap", anotherButtonListener)
end

startButtonListeners = function(event)
   --在这里做一些事情
end
anotherButtonListener = function(event)
   --在这里为credits做一些事情
end

Main()  --记得实际调用Main使其运行

在Lua中,没有声明的主函数,它只是按顺序运行所有内容。记住,你不需要像在C中那样编写主函数,而更像Python,它将仅运行你编写的内容。

编辑:为什么不让我们看到你得到的错误,这样我们就可以更好地帮助你了?但是扫描代码确实有情况。newGroup那行代码。

参考上面编辑过的代码。

2015-02-18 01:39:38