Hi,
My problem is about how manage tap event BEFORE touch event on a display object.
As you may know, listening to one display object for both touch and tap events will fire the touch event phases BEFORE the tap event fires.
The context
I have a display object
I can drag and drop this object : I use touch event for this with began / move / end phases. Classic stuff. At the end phase, when the object is dropped, a sound is played, and some actions occurs.
I can double taped this object : different actions occurs when I double tapped.
What I’d like to do :
I would like NOT execute the code in my touch listener begin/move/end phases WHEN I double tapped the object.
Any help or idea would be appreciate
Thanks
Sincerely,
Olivier [import]uid: 160159 topic_id: 36929 reply_id: 336929[/import]
The tap and touch events are two different events, and the touch events get processed first.
You could try to write your touch handler so that a brief touch is interpreted as tap, and a longer touch would then be a touch. That way you do not have to worry about watching for a tap event. You would need to set up a time, and check how long the touch occurred in the ended phase.
Here is an example:
[lua]
local handleButtonTouch
local tapTimer
local newButton
local clock = os.clock
local function main()
newButton = display.newImage(“button.png”)
newButton.name =“button”
newButton.touch = handleButtonTouch
newButton:addEventListener(“touch”, newButton)
end
function handleButtonTouch(self, event)
if event.phase == “began” then
tapTimer = clock()
– specify the global touch focus
display.getCurrentStage():setFocus( self )
self.isFocus = true
elseif self.isFocus then
if event.phase == “moved” then
– do something here; or not
newButton.x = event.x
newButton.y = event.y
elseif event.phase == “ended” or event.phase == “cancelled” then
The tap and touch events are two different events, and the touch events get processed first.
You could try to write your touch handler so that a brief touch is interpreted as tap, and a longer touch would then be a touch. That way you do not have to worry about watching for a tap event. You would need to set up a time, and check how long the touch occurred in the ended phase.
Here is an example:
[lua]
local handleButtonTouch
local tapTimer
local newButton
local clock = os.clock
local function main()
newButton = display.newImage(“button.png”)
newButton.name =“button”
newButton.touch = handleButtonTouch
newButton:addEventListener(“touch”, newButton)
end
function handleButtonTouch(self, event)
if event.phase == “began” then
tapTimer = clock()
– specify the global touch focus
display.getCurrentStage():setFocus( self )
self.isFocus = true
elseif self.isFocus then
if event.phase == “moved” then
– do something here; or not
newButton.x = event.x
newButton.y = event.y
elseif event.phase == “ended” or event.phase == “cancelled” then
The tap and touch events are two different events, and the touch events get processed first.
You could try to write your touch handler so that a brief touch is interpreted as tap, and a longer touch would then be a touch. That way you do not have to worry about watching for a tap event. You would need to set up a time, and check how long the touch occurred in the ended phase.
Here is an example:
[lua]
local handleButtonTouch
local tapTimer
local newButton
local clock = os.clock
local function main()
newButton = display.newImage(“button.png”)
newButton.name =“button”
newButton.touch = handleButtonTouch
newButton:addEventListener(“touch”, newButton)
end
function handleButtonTouch(self, event)
if event.phase == “began” then
tapTimer = clock()
– specify the global touch focus
display.getCurrentStage():setFocus( self )
self.isFocus = true
elseif self.isFocus then
if event.phase == “moved” then
– do something here; or not
newButton.x = event.x
newButton.y = event.y
elseif event.phase == “ended” or event.phase == “cancelled” then
The tap and touch events are two different events, and the touch events get processed first.
You could try to write your touch handler so that a brief touch is interpreted as tap, and a longer touch would then be a touch. That way you do not have to worry about watching for a tap event. You would need to set up a time, and check how long the touch occurred in the ended phase.
Here is an example:
[lua]
local handleButtonTouch
local tapTimer
local newButton
local clock = os.clock
local function main()
newButton = display.newImage(“button.png”)
newButton.name =“button”
newButton.touch = handleButtonTouch
newButton:addEventListener(“touch”, newButton)
end
function handleButtonTouch(self, event)
if event.phase == “began” then
tapTimer = clock()
– specify the global touch focus
display.getCurrentStage():setFocus( self )
self.isFocus = true
elseif self.isFocus then
if event.phase == “moved” then
– do something here; or not
newButton.x = event.x
newButton.y = event.y
elseif event.phase == “ended” or event.phase == “cancelled” then