【发布时间】:2017-12-31 11:32:23
【问题描述】:
我的按钮和场景更改有问题,我的标题屏幕场景中的按钮既可以工作又可以直接到相应的屏幕,但它们只会执行一次。所以我无法导航到选项,然后返回标题屏幕,然后再次返回选项 - 我不知道为什么?
这是我的标题屏幕文件:
module(..., package.seeall)
local assetPath = "assets/"
local mainGroup = display.newGroup()
function new()
local ui = require("ui")
local titleScreen = display.newImageRect(assetPath .. "mainMenu.png", display.contentWidth, display.contentHeight)
titleScreen.x = display.contentWidth / 2
titleScreen.y = display.contentHeight / 2
mainGroup:insert(titleScreen)
local onPlayTouch = function( event )
if event.phase == "release" then
director:changeScene("gameScreen")
end
end
local playButton = ui.newButton{
defaultSrc = assetPath .. "playnowbtn.png",
defaultX = 222,
defaultY = 62,
overSrc = assetPath .. "playnowbtn-over.png",
overX = 222,
overY = 62,
onEvent = onPlayTouch
}
playButton.x = display.contentWidth / 2
playButton.y = 50;
mainGroup:insert( playButton )
local onOptionTouch = function( event )
if event.phase == "release" then
director:changeScene("optionsScreen")
end
end
local optionButton = ui.newButton{
defaultSrc = assetPath .. "playnowbtn.png",
defaultX = 222,
defaultY = 62,
overSrc = assetPath .. "playnowbtn-over.png",
overX = 222,
overY = 62,
onEvent = onOptionTouch
}
optionButton.x = display.contentWidth / 2
optionButton.y = 190;
mainGroup:insert( optionButton )
return mainGroup
end
我的选项文件如下所示:
module(..., package.seeall)
function new()
local assetPath = "assets/"
local localGroup = display.newGroup()
local background = display.newImage (assetPath .."optionsScreen.png")
localGroup:insert(background)
local onBackTouch = function( event )
if event.phase == "release" then
director:changeScene("titleScreen")
end
end
local backButton = ui.newButton{
defaultSrc = assetPath .. "playnowbtn.png",
defaultX = 222,
defaultY = 62,
overSrc = assetPath .. "playnowbtn-over.png",
overX = 222,
overY = 62,
onEvent = onBackTouch
}
backButton.x = display.contentWidth / 2
backButton.y = display.contentHeight / 2
localGroup:insert(backbutton)
return localGroup
end
现在按钮显示在选项场景中并响应触摸,但不直接返回标题屏幕。
我想我对分组感到困惑,只将图像分配给场景而不是整个游戏?
谁能帮帮我,谢谢。
编辑:
单击按钮时,我也遇到了这些运行时错误。
运行时错误 /Users/Lewis/Desktop/proj/optionsScreen.lua:30:错误:预期的表。如果这是一个函数调用,您可能使用了 '.'代替 ':' 堆栈回溯: [C]: ? [C]:在函数“插入”中 /Users/Lewis/Desktop/proj/optionsScreen.lua:30:在功能“新”中 /Users/Lewis/Desktop/proj/director.lua:118:在函数“loadScene”中 /Users/Lewis/Desktop/proj/director.lua:415:在函数“changeScene”中 /Users/Lewis/Desktop/proj/titlescreen.lua:67:在函数“onEvent”中 /Users/Lewis/Desktop/proj/ui.lua:94:在功能中 ?: 在函数中 运行时错误 /Users/Lewis/Desktop/proj/director.lua:151:尝试调用字段“unloadMe”(零值) 堆栈回溯: [C]:在函数“unloadMe”中 /Users/Lewis/Desktop/proj/director.lua:151:在函数“_listener”中 ?: 在函数中 ?: 在函数中
【问题讨论】:
标签: lua navigation coronasdk