hum… but delete theses 2 lines generated other focus pb…
is there a way to make that the “tap” function will not be cancelled by the 2 lines of code below ?
hum… but delete theses 2 lines generated other focus pb…
is there a way to make that the “tap” function will not be cancelled by the 2 lines of code below ?
Like I said before don’t mix tap and touch on the same element. Do everything in touch. You can time the difference between began and ended and if under say 300 ms then treat as tap otherwise treat as touch.
i added a timer and now it really seems to solve the pb :
local function clicSound_before(event)
timer.performWithDelay(1, function() clicSound(event) end)
end
i made little tests, and the “tap” function seems to be never more cancelled !
sgs : the problem if you count 300 ms during began and ended in “touch” event, is that you don’t know if, when the “ended” event is executed, the users has always is pointer above your button or not ?
I think this would all be so much easier solved if you used a widget button instead of your own home-brewed button…
https://docs.coronalabs.com/api/library/widget/newButton.html
Use both the “onPress” and “onRelease” options in the button constructor. In the “onPress” listener function, play your click sound. In the “onRelease” listener function, start the game. Simple and done.
Brent
from what i have noticed, it seems that having both tap and touch on the same object will trigger both if you want or not.
you can handle conditions in code but you cant prevent the event.
i have cases where i need touch to be able to handle drag events for the object while at the same time i need tap on the same object to be able to handle double tap (win32 app).
If you dont have to, using one or the other per object makes life easier.
I agree with Brent. Use exiting core functionality whenever possible - it saves all this!
To address your question… don’t “set focus” to the button/image and then you will not have this problem. That is only required if you want to direct touch events to an object when the touch points exist outside the bounds of the object for things like dragging.
For a simple button implementation setting focus is NOT required and NOT advised.