我正在使用Corona SDK和Director 1.4来创建应用。我的目标是在单击按钮(btn_play
)时打开弹出窗口。
然而,我遇到了一个问题。单击btn_play
时,它会触发openPopup(e)
以及changeScene(e)
(因为后台设置为执行该功能)。如何在单击changeScene(e)
按钮时停止执行btn_play
功能?
这是我的游戏屏幕代码:
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
答案 0 :(得分:5)
只需将return
放在功能的末尾即可。它将阻止touch
到底层对象。
function openPopup(e)
if(e.phase == "ended") then
director:openPopUp(e.target.scene);
return true; -- put this in your function.
end
end
保持编码..............:)