(Game Edition, iPad target)
Something doesn’t make any sense to me.
I have 2 boxes (1 red, 1 blue) on screen. I set up a touch handler for these boxes.
I also have a screen touch handler.
When I touch one of the boxes, I want it to capture all future events until event.phase = “ended”. I want no other handlers to get called.
I followed the docs and:
- at box handler event.phase = “began”, set the focus to the touched box.
- at box handler event.phase = “ended”, set the focus to nil.
- box handler always return true.
Yet, the screen touch handler always gets invoked.
Here is my code:
local screenTouched = function( event )
print ("screenTouched")
return true
end
Runtime:addEventListener( "touch", screenTouched )
local boxTouched = function( event )
print ("drag event "..event.phase.." for "..event.target.name)
if event.phase == "began" then
display.getCurrentStage():setFocus(event.target)
elseif event.phase == "ended" then
display.getCurrentStage():setFocus(nil)
end
return true
end
local box1 = display.newRect(display.contentWidth/2 - 60, display.contentHeight/2, 100, 100)
local box2 = display.newRect(display.contentWidth/2 + 60, display.contentHeight/2, 100, 100)
box1:setFillColor(100, 200, 250)
box2:setFillColor(250, 100, 100)
box1:addEventListener( "touch", boxTouched)
box2:addEventListener( "touch", boxTouched)
box1.name = "blue box"
box2.name = "red box"
If you run this, you’ll see that if I touch and drag box1, the handler for box2 never gets called. That’s good.
But, the screen touch handler always gets called, regardless of where the current touch is. Not good.
Thanks for any advice.
Alex
[import]uid: 3473 topic_id: 2314 reply_id: 302314[/import]