Thanks,
I tried that, but even with both flags, the menu does not respond properly to tap events.
Here is the code (without the new flags), if anyone has some insight about this problem, I’ll be very grateful.
First, the code for the touch event that allows the user to drag the menu up and down:
local turnMenuBarOn --used in function dragMenu, defined outside due to scope problem I couldnt solve when declared within the function
local function dragMenu(event)
local t = event.target
local phase = event.phase
if "began" == phase then
display.getCurrentStage():setFocus( t, event.id )
t.isFocus = true
-- Store initial position
t.y0 = event.y
elseif t.isFocus then
if "moved" == phase then
local originalMenuY
if menuBarOn == true then
originalMenuY = display.screenOriginY
else
originalMenuY = display.screenOriginY-70
end
--how many pixels to move the menu bar up or down
local moveAmount = event.y - t.y0
if moveAmount \> 0 then
turnMenuBarOn = true --at the end of the function use this variable to decide whether to transition the menu to the full on or full off position
else
turnMenuBarOn = false
end
--don't let the move amount be greater then 70 pixels
if moveAmount \> 70 then moveAmount = 70 end
--move the menu bar by the calculated amount
if (originalMenuY + moveAmount) \< display.screenOriginY then
menuBar.y = originalMenuY + moveAmount
end
menuBar.alpha = 1
elseif "ended" == phase or "cancelled" == phase then
--lock menu in full down position or full up position, depending on menuBarOn state
if turnMenuBarOn then
transition.to(menuBar,{time=300,alpha=1,y=display.screenOriginY})
menuBarOn = true
else
transition.to(menuBar,{time=300,alpha=0,y=display.screenOriginY-70})
menuBarOn = false
end
display.getCurrentStage():setFocus( t, nil )
t.isFocus = false
end
end
return true
end
mapArea:addEventListener("touch", dragMenu)
Next, the code for the tap event which triggers a show/hide menu function:
local function showHideMenuBar()
if menuBarOn == false then transition.to(menuBar,{time=300,alpha=1,y=display.screenOriginY})
else transition.to(menuBar,{time=300,alpha=0,y=display.screenOriginY-70}) end
menuBarOn = not menuBarOn
end --end showHideMenu()
local function callShowHideMenuBar(e)
--we use this function so that we can call showHideMenu() from other areas in the code (not just from the tap events)
showHideMenuBar()
return true
end
mapArea:addEventListener("tap", callShowHideMenuBar)
Thanks again! [import]uid: 33608 topic_id: 9763 reply_id: 36184[/import]