The button class handles clicks/touches (taps?). Your click event function could wait for a second click before executing. Or were you looking for something else?
What's the usual use case for this in an app? For navigation or having the user click something as fast as they can? Just adding a counter in your click event would provide the same functionality right, or maybe I'm forgetting something?
@avo, I think tap count is mainly used for gestures e.g. double tap with double finger. But I also want to hear other use cases.
On the other hand its implementation is a little bit tricky: Consecutive taps should be near to each other (e.g. 20-30 pixels) and the delay between them should be small.
Well I was thinking if it was used with the button class which would eliminate the need for proximity check, and the delay check wouldn't be hard I don't think. I can see how it would get more complicated if the app is just listening for a double/multi tap all the time.
Im my case, I have a sprite that can be dragged, and tapping should preform a rotation, but I don't want to write debounce code, if its in the roadmap already.
First, THANK YOU, Atilim and Deniz, for making your wonderful product available for free.
I really, REALLY want to use Gideros to make my first app, but it MUST have a single-/double-/triple-touch recognition mechanism. It is essential to the app I want to make.
In order for my app to react as responsively as possible to single-, double- and triple-touches, I want it to act IMMEDIATELY upon the third touch (and not wait for the user's thumb to be lifted off the screen). [Please note: That is also why I am being careful to use the word "touch", instead of the word "tap".]
I also wish to make the triple-touch time limit adjustable by the user.
I cannot speak Lua (yet), so I wrote the mechanism in English. Would someone be kind enough to translate it into (Giderosian) Lua for me? Here it is:
=========== --Triple-touch Mechanism
-- Set "Touch3TimeLimit". Touch3TimeLimit = 400 --
-- 3 Touches If the screen is touched 3 times within [Touch3TimeLimit] milliseconds, (...do Thing C). --
-- 2 Touches If the screen is only touched twice within [Touch3TimeLimit] milliseconds, (...do Thing . --
-- Only 1 Touch If the screen is only touched once within [Touch3TimeLimit] milliseconds, (...do Thing A) --
--End of Triple-touch Mechanism ===========
This is designed for users using only one thumb, touching ("tapping") anywhere on the screen. As Atilim's comment ("Consecutive taps should be near to each other") illustrates, I believe that double- and triple-touching should only be implemented on a whole-screen basis (that is, the entire screen should be like one big button), with touch location being irrelevant (no discrete buttons, only the entire screen). Otherwise, difficulties can arise in some situations for some users (especially those with motor problems).
Thanks very much. Platypus
Kate's Catalogue of Travelling Theatre Centres : Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour. She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
-- Set "Touch2TimeLimit". Touch2TimeLimit = 200 --
-- Held If a touch begins but does not end within [Touch2TimeLimit*2/3] milliseconds, (...do Thing C). --
-- 2 Touches If the screen is touched twice within [Touch2TimeLimit] milliseconds, (... immediately do Thing . --
-- Only 1 Touch If the screen is only touched once within [Touch2TimeLimit] milliseconds, (...do Thing A) --
--End of "Hold / Single-touch / Double-touch Mechanism" ===========
If an expert would be kind enough to translate that one into Giderosian Lua too, I would be very grateful.
Thank you very much. Platypus
Kate's Catalogue of Travelling Theatre Centres : Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour. She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
I will study it and eventually try to implement it. Thank you very, very much.
Platypus
Kate's Catalogue of Travelling Theatre Centres : Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour. She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
Thank you for your warm welcome. I am very excited about getting involved with this friendly group of esteemed gentlemen (and ladies?).
Are there any ladies here?
Platypus
Kate's Catalogue of Travelling Theatre Centres : Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour. She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
In the code you kindly provided (above), do you mind if I change "Event.TOUCHES_BEGIN" to "Event.MOUSE_DOWN" (and "Event.TOUCHES_END" to "Event.MOUSE_UP")?
If I do that, is there any other part of the code that needs to be changed?
I won't be using two-fingered simultaneous touches ("multitouch") in my app, only single-thumbed consecutive touches. Is "Event.MOUSE_..." a more efficient choice than "Event.TOUCHES_..." in this case?
I might as well mention what I am making: I am making a (simple, non-interactive) comic book. Each "page" is merely a PNG image that fills the screen. The book has over 200 pages. I want to be able to name the images as follows:
...and instruct the app to display the "next" image (in numerical order of filename) when the user taps (briefly touches) the screen once; the "previous" image when the user taps the screen twice; and the menu screen (scene) when the user holds his/her thumb on the screen for a moment.
Kate's Catalogue of Travelling Theatre Centres : Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour. She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
@Platypus yes sure you can do that, don't know if it would give anything performance wise, but probably it is easier to deal with it logically, if not dealing with multiple events
Then you would need to change onTouchesBegin method from e.touch. x to e.x and from e.touch.y to e.y
function scene:onTouchBegin(e)if self:hitTestPoint(e.x, e.y)thenif self.touchStarted ==falsethen
self.touchStarted =os.timer()*1000endifnot self.timeStarted then
self.timeStarted =os.timer()*1000end
self.touchCount = self.touchCount + 1if(self.touchCount >=2)then
self.check()endendend
And also inside Gideros project right click on your project name in file structure tree and select properties, there under input tab you should check (if it is not already checked) Mouse events generate touch events to make it work on devices.
Kate's Catalogue of Travelling Theatre Centres : Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour. She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
Did you eventually decide to write your own "double click" code? If so, would you mind showing us?
Kate's Catalogue of Travelling Theatre Centres : Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour. She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
I copied and pasted your original code into a blank "main.lua" file, but the programme does not do anything. Is it necessary to run it on a mobile device? I am using the desktop Gideros Player. (Does "os.timer" work on the desktop?)
Is it necessary for me to add any support files or any other code to make it work? Please forgive my ignorance. I am a complete beginner to computer programming.
Here is your code again, with a few "print" commands added:
print("Yo, the output printer is WORKING.")--create scene class
scene = Core.class()--scene constructorfunction scene:init()--init some variables
self.timeLimit =200
self.touchCount =0
self.timerStarted =false
self.touchStarted =false--add events
self:addEventListener(Event.TOUCHES_BEGIN, self.onTouchBegin, self)
self:addEventListener(Event.TOUCHES_END, self.onTouchEnd, self)
self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)endfunction scene:onTouchBegin(e)if self:hitTestPoint(e.touch.x, e.touch.y)thenif self.touchStarted ==falsethen
self.touchStarted =os.timer()*1000endifnot self.timeStarted then
self.timeStarted =os.timer()*1000end
self.touchCount = self.touchCount + 1if(self.touchCount >=2)then
self.check()endendendfunction scene:onTouchEnd(e)if self.touchStarted then
self.touchStarted =falseendendfunction scene:onEnterFrame()if self.touchStart thenifos.timer()*1000 - self.touchStart >= self.timeLimit*2/3then
self.touchCount =0
self:check()
self:C()endendif self.timeStarted thenifos.timer()*1000 - self.timeStarted >= self.timeLimit then
self:check()endendendfunction scene:check()
self.timerStarted =falseif self.touchCount >=2then--do B
self:B()elseif self.touchCount ==1then
self:A()end
self.touchCount =0end--thing cfunction scene:C()print("THE USER HELD HIS/HER/ITS FINGER DOWN FOR A WHILE.")end--thing bfunction scene:B()print("THE USER DID A DOUBLE TAP!")end--thing afunction scene:A()print("THAT WAS JUST A SINGLE TAP")end
Kate's Catalogue of Travelling Theatre Centres : Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour. She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
@Platypus oh yes it was not meant to work out of the box. There are multiple issues as: if object is not added to the stage, it will not receive touch events at all. to add object to the stage it should inherit from sprite even if all above done hitTestPoint method would never return true, as there are no contents for object.
Here is a quick working prototype for you to test, which works on whole screen
Kate's Catalogue of Travelling Theatre Centres : Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour. She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
Kate's Catalogue of Travelling Theatre Centres : Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour. She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
Kate's Catalogue of Travelling Theatre Centres : Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour. She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
Comments
https://github.com/gideros/Button
http://developer.anscamobile.com/reference/index/events/tap
I used Corona for awhile, and tap events can be very useful, just as clicking and dragging and just clicking are different but both useful inputs.
On the other hand its implementation is a little bit tricky: Consecutive taps should be near to each other (e.g. 20-30 pixels) and the delay between them should be small.
my 2 cents
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
I am new here. This is my first post.
First, THANK YOU, Atilim and Deniz, for making your wonderful product available for free.
I really, REALLY want to use Gideros to make my first app, but it MUST have a single-/double-/triple-touch recognition mechanism. It is essential to the app I want to make.
In order for my app to react as responsively as possible to single-, double- and triple-touches, I want it to act IMMEDIATELY upon the third touch (and not wait for the user's thumb to be lifted off the screen). [Please note: That is also why I am being careful to use the word "touch", instead of the word "tap".]
I also wish to make the triple-touch time limit adjustable by the user.
I cannot speak Lua (yet), so I wrote the mechanism in English. Would someone be kind enough to translate it into (Giderosian) Lua for me? Here it is:
===========
--Triple-touch Mechanism
-- Set "Touch3TimeLimit".
Touch3TimeLimit = 400
--
-- 3 Touches
If the screen is touched 3 times within [Touch3TimeLimit] milliseconds, (...do Thing C).
--
-- 2 Touches
If the screen is only touched twice within [Touch3TimeLimit] milliseconds, (...do Thing .
--
-- Only 1 Touch
If the screen is only touched once within [Touch3TimeLimit] milliseconds, (...do Thing A)
--
--End of Triple-touch Mechanism
===========
This is designed for users using only one thumb, touching ("tapping") anywhere on the screen. As Atilim's comment ("Consecutive taps should be near to each other") illustrates, I believe that double- and triple-touching should only be implemented on a whole-screen basis (that is, the entire screen should be like one big button), with touch location being irrelevant (no discrete buttons, only the entire screen). Otherwise, difficulties can arise in some situations for some users (especially those with motor problems).
Thanks very much.
Platypus
Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour.
She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
===========
-- "Hold / Single-touch / Double-touch Mechanism"
-- Set "Touch2TimeLimit".
Touch2TimeLimit = 200
--
-- Held
If a touch begins but does not end within [Touch2TimeLimit*2/3] milliseconds, (...do Thing C).
--
-- 2 Touches
If the screen is touched twice within [Touch2TimeLimit] milliseconds, (... immediately do Thing .
--
-- Only 1 Touch
If the screen is only touched once within [Touch2TimeLimit] milliseconds, (...do Thing A)
--
--End of "Hold / Single-touch / Double-touch Mechanism"
===========
If an expert would be kind enough to translate that one into Giderosian Lua too, I would be very grateful.
Thank you very much.
Platypus
Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour.
She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
Thank you, @ar2rsawseen. That looks amazing.
I will study it and eventually try to implement it.
Thank you very, very much.
Platypus
Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour.
She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
Thank you for your warm welcome. I am very excited about getting involved with this friendly group of esteemed gentlemen (and ladies?).
Are there any ladies here?
Platypus
Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour.
She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
Likes: Caroline
In the code you kindly provided (above), do you mind if I change "Event.TOUCHES_BEGIN" to "Event.MOUSE_DOWN" (and "Event.TOUCHES_END" to "Event.MOUSE_UP")?
If I do that, is there any other part of the code that needs to be changed?
I won't be using two-fingered simultaneous touches ("multitouch") in my app, only single-thumbed consecutive touches. Is "Event.MOUSE_..." a more efficient choice than "Event.TOUCHES_..." in this case?
I might as well mention what I am making:
I am making a (simple, non-interactive) comic book. Each "page" is merely a PNG image that fills the screen. The book has over 200 pages. I want to be able to name the images as follows:
0000.png
0010.png
0020.png
0030.png
.
.
2550.png
2560.png
...and instruct the app to display the "next" image (in numerical order of filename) when the user taps (briefly touches) the screen once; the "previous" image when the user taps the screen twice; and the menu screen (scene) when the user holds his/her thumb on the screen for a moment.
Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour.
She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
Then you would need to change onTouchesBegin method from e.touch. x to e.x and from e.touch.y to e.y
Platypus
Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour.
She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
Did you eventually decide to write your own "double click" code? If so, would you mind showing us?
Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour.
She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
Ar2rs, I can't seem to make it work. Please help!
I copied and pasted your original code into a blank "main.lua" file, but the programme does not do anything. Is it necessary to run it on a mobile device? I am using the desktop Gideros Player. (Does "os.timer" work on the desktop?)
Is it necessary for me to add any support files or any other code to make it work? Please forgive my ignorance. I am a complete beginner to computer programming.
Here is your code again, with a few "print" commands added:
Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour.
She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
There are multiple issues as:
if object is not added to the stage, it will not receive touch events at all.
to add object to the stage it should inherit from sprite
even if all above done hitTestPoint method would never return true, as there are no contents for object.
Here is a quick working prototype for you to test, which works on whole screen
Thanks, legend.
Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour.
She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
It's BRILLIANT!
Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour.
She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
Here are the answers you probably seek:
@ar2rsawseen's attachment, "Test.zip" (above), and/or
@Magnusviri's blog, here: http://blog.magnusviri.com/mobile-game-programming-lesson-6.html (Scroll down to "Instant Multi-tap", "Delayed Multi-tap" and "Press & Hold".)
Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour.
She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.