Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Tap, Click and double click events? — Gideros Forum

Tap, Click and double click events?

dnhkngdnhkng Member
edited May 2012 in General questions
Is there preset events for these UI actions, or do we have to code them ourselves?

Likes: shivaj, bradp602

+1 -1 (+2 / -0 )Share on Facebook

Comments

  • avoavo Member
    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?

    https://github.com/gideros/Button
  • dnhkngdnhkng Member
    corona has touch events, and also tap events.
    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.
  • avoavo Member
    Oh I see so it counts how many times a user has tapped. No I don't think Gideros has that built in.
  • atilimatilim Maintainer
    edited May 2012
    Currently we don't support but I've added it to the roadmap: http://bugs.giderosmobile.com/issues/107
  • avoavo Member
    edited May 2012
    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?
  • atilimatilim Maintainer
    edited May 2012
    @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.

    my 2 cents
  • avoavo Member
    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.
  • @dnhkng have you seen http://giderosmobile.com/forum/discussion/946/compatibility-library-for-csdk that is the compatibility layer for C*SDK, i.e. you can use most (currently) of the features of C*SDK in Gideros (display, timer, transition, touches, Runtime)
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    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
  • dnhkngdnhkng Member
    edited May 2012
    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.
  • Hi, everyone.

    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 B).
    --

    -- 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.
  • PlatypusPlatypus Member
    edited March 2013
    The following alternative might feel even more responsive for users:


    ===========
    -- "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 B).
    --

    -- 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.
  • ar2rsawseenar2rsawseen Maintainer
    @Platypus Here's something from the top of the head, not tested, but might help to get you started ;)
    --create scene class
    scene = Core.class()
     
    --scene constructor
    function 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)
    end
     
    function scene:onTouchBegin(e)
        if self:hitTestPoint(e.touch.x, e.touch.y) then
            if self.touchStarted == false then
                self.touchStarted = os.timer()*1000
            end
            if not self.timeStarted then
                self.timeStarted = os.timer()*1000
            end
            self.touchCount = self.touchCount + 1
            if(self.touchCount >= 2) then
                self.check()
            end
        end
    end
     
    function scene:onTouchEnd(e)
        if self.touchStarted then
            self.touchStarted = false
        end
    end
     
    function scene:onEnterFrame()
            if self.touchStart then
                if os.timer()*1000 - self.touchStart >= self.timeLimit*2/3 then
                     self.touchCount = 0
                     self:check()
                     self:C()
                end
            end
            if self.timeStarted then
                if os.timer()*1000 - self.timeStarted >= self.timeLimit then
                      self:check()
                end
           end
    end
     
    function scene:check()
        self.timerStarted = false
        if self.touchCount >= 2 then
            --do B
            self:B()
        elseif self.touchCount == 1 then
            self:A()
        end
     
        self.touchCount = 0
    end
     
    --thing c
    function scene:C()
    end
     
    --thing b
    function scene:B()
    end
     
    --thing a
    function scene:A()
    end
  • Wow!
    Thank you, @ar2rsawseen. That looks amazing.

    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.
  • Dear @Scouser,

    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.
  • ar2rsawseenar2rsawseen Maintainer
    @Platypus sure there is, @Deniz, @Caroline and @mysps from the top of my head, but there must be more :)

    Likes: Caroline

    +1 -1 (+1 / -0 )Share on Facebook
  • PlatypusPlatypus Member
    edited March 2013
    Dear @ar2rsawseen,

    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.

    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.
  • ar2rsawseenar2rsawseen Maintainer
    @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) then
            if self.touchStarted == false then
                self.touchStarted = os.timer()*1000
            end
            if not self.timeStarted then
                self.timeStarted = os.timer()*1000
            end
            self.touchCount = self.touchCount + 1
            if(self.touchCount >= 2) then
                self.check()
            end
        end
    end
    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.
  • Thanks very much, @ar2rsawseen.
    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.
  • @dnhkng,

    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.
  • @ar2rsawseen

    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:
    print("Yo, the output printer is WORKING.")
     
     
    --create scene class
    scene = Core.class()
     
    --scene constructor
    function 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)
    end
     
    function scene:onTouchBegin(e)
        if self:hitTestPoint(e.touch.x, e.touch.y) then
            if self.touchStarted == false then
                self.touchStarted = os.timer()*1000
            end
            if not self.timeStarted then
                self.timeStarted = os.timer()*1000
            end
            self.touchCount = self.touchCount + 1
            if(self.touchCount >= 2) then
                self.check()
            end
        end
    end
     
    function scene:onTouchEnd(e)
        if self.touchStarted then
            self.touchStarted = false
        end
    end
     
    function scene:onEnterFrame()
            if self.touchStart then
                if os.timer()*1000 - self.touchStart >= self.timeLimit*2/3 then
                     self.touchCount = 0
                     self:check()
                     self:C()
                end
            end
            if self.timeStarted then
                if os.timer()*1000 - self.timeStarted >= self.timeLimit then
                      self:check()
                end
           end
    end
     
    function scene:check()
        self.timerStarted = false
        if self.touchCount >= 2 then
            --do B
            self:B()
        elseif self.touchCount == 1 then
            self:A()
        end
     
        self.touchCount = 0
    end
     
    --thing c
    function scene:C()
    print("THE USER HELD HIS/HER/ITS FINGER DOWN FOR A WHILE.")
    end
     
    --thing b
    function scene:B()
    print("THE USER DID A DOUBLE TAP!")
    end
     
    --thing a
    function 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.
  • ar2rsawseenar2rsawseen Maintainer
    @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 ;)

    zip
    zip
    Test.zip
    1K
  • @ar2rsawseen,
    Thanks, legend.

    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.
  • @ar2rsawseen,

    It's BRILLIANT!
    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.
  • Dear future readers of this thread,

    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".)
    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.
Sign In or Register to comment.