Lua 停止Corona SDK中的事件传播
我正在使用Corona SDK和Director 1.4创建一个应用程序。我的目标是在点击按钮(Lua 停止Corona SDK中的事件传播,lua,coronasdk,corona-director,Lua,Coronasdk,Corona Director,我正在使用Corona SDK和Director 1.4创建一个应用程序。我的目标是在点击按钮(btn\u play)时打开一个弹出窗口 然而,我遇到了一个问题。当点击btn\u play时,它会触发openPopup(e)以及changesecene(e)(背景设置为执行该功能)。单击btn\u play按钮时,如何停止执行功能changeScene(e) 以下是我的游戏屏幕代码: module(..., package.seeall) local localGroup function
btn\u play
)时打开一个弹出窗口
然而,我遇到了一个问题。当点击btn\u play
时,它会触发openPopup(e)
以及changesecene(e)
(背景设置为执行该功能)。单击btn\u play
按钮时,如何停止执行功能changeScene(e)
以下是我的游戏屏幕代码:
module(..., package.seeall)
local localGroup
function new()
localGroup = display.newGroup();
-- Background Image
local background = display.newImageRect("background.jpg", display.contentWidth, display.contentHeight )
background:setReferencePoint( display.TopLeftReferencePoint )
background.x, background.y = 0, 0
background.scene = "scene_menu";
-- Play button
local btn_play = display.newImageRect("grass.png", 320, 82 )
btn_play:setReferencePoint( display.CenterReferencePoint )
btn_play.x = display.contentWidth * 0.5
btn_play.y = 600
btn_play.scene = "inventory"
localGroup:insert(background);
localGroup:insert(btn_play);
function changeScene(e)
if(e.phase == "ended") then
director:changeScene(e.target.scene);
end
end
function openPopup(e)
if(e.phase == "ended") then
director:openPopUp(e.target.scene);
end
end
background:addEventListener("touch", changeScene);
btn_play:addEventListener("touch", openPopup);
return localGroup;
end
只需在函数末尾添加
return
。它将阻止触摸底层对象
function openPopup(e)
if(e.phase == "ended") then
director:openPopUp(e.target.scene);
return true; -- put this in your function.
end
end
继续编码………..) 非常好。很好用!完全忽略了返回真值的重要性
伟大的解决方案!谢谢。只是一个问题,为什么用分号?@Rayjax:分号不是强制性的。它只是用来显示行尾,所以不需要在lua中使用它们?你只是让我怀疑:)