Reputation: 54212
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.
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
Upvotes: 3
Views: 1754
Reputation: 7390
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.............. :)
Upvotes: 5