在Corona SDK中停止事件传播 [英] Stop event propagation in Corona SDK
问题描述
我正在使用Corona SDK和Director 1.4创建一个应用程序.我的目标是在单击按钮(btn_play
)时打开一个弹出窗口.
I'm using Corona SDK, and Director 1.4 to create an app. My goal is to open a popup when the button (btn_play
) is clicked.
但是,我遇到了一个问题.单击btn_play
时,它会触发openPopup(e)
和changeScene(e)
(因为将背景设置为执行该功能).单击btn_play
按钮时如何停止执行功能changeScene(e)
?
However, I encounter a problem. When the btn_play
is clicked, it triggers openPopup(e)
as well as changeScene(e)
(as the background is set to execute the function). How can I stop the function changeScene(e)
from executing when clicking the btn_play
button?
这是我的游戏屏幕代码:
Here is my game screen's codes:
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
放在函数的末尾即可.它将防止touch
成为基础对象.
Just put return
at the end of your function. It will prevent the touch
to underlying objects.
function openPopup(e)
if(e.phase == "ended") then
director:openPopUp(e.target.scene);
return true; -- put this in your function.
end
end
继续编码..............:)
Keep Coding.............. :)
这篇关于在Corona SDK中停止事件传播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!