During a touch event I can call display.getCurrentStage():setFocus(object) so that following touch events all apply to the object. During a touch event how can I check if focus is set to any object?
What I want to do is 'release' the object when the users finger moves out of the object bounds, which I do using display.getCurrentStage():setFocus(nill). However while the event is still in the "moved" phase I need to set focus to the next object once the previous object has been 'released'.
The following unfinished code might help explain.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | function card:touch(event) if event.phase == "began" then display.getCurrentStage():setFocus( card ) -- display selection elseif event.phase == "moved" then if focusIsSet???? then if card.isOutOfBounds(event) then display.getCurrentStage():setFocus(nil) -- clear selection return false end else display.getCurrentStage():setFocus( card ) -- display selection elseif event.phase == "ended" then display.getCurrentStage():setFocus(nil) -- clear selection end return true end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | function card:touch(event) if event.phase == "began" then display.getCurrentStage():setFocus( card ) event.target.isFocus = true -- display selection elseif event.phase == "moved" then if event.target.isFocus then if card.isOutOfBounds(event) then display.getCurrentStage():setFocus(nil) -- clear selection return false end else display.getCurrentStage():setFocus( card ) -- display selection elseif event.phase == "ended" then display.getCurrentStage():setFocus(nil) event.target.isFocus = false -- clear selection end return true end |
Great, thanks.
I can see I'm going to have to break free of the static language mindset.
views:1648 update:2011/11/25 8:45:21