Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Simple Swipe Right? — Gideros Forum

Simple Swipe Right?

edited December 2017 in General questions
I apologize if this is a stupid question, but I got the hang of mouse down and mouse up, but how would I detect a swipe to the right?

Thank you!

Comments

  • You should use an on touch event, then check to see if the the movement is going right over time, eg start a counter, if the event x is moving a specific delta or more and it has done it for x consecutive events then it's it's a swipe to the right.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • the search is not working on the forum, yet i think somebody made a helper class for gestures in the past. search on google for gideros gesture maybe.
  • There is a ready-made "Gestures" class, I didn't try it myself yet, but I guess it works :)
    http://appcodingeasy.com/Gideros-Mobile/Detecting-Gestures-in-Gideros

    Likes: oleg

    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
    +1 -1 (+1 / -0 )Share on Facebook
  • After adding Gestures class in your project the code is so simple to use with Scenemanager.
    Add this code snippet to all your secenes to the init function.
    local function callback(name)
    	if name=='Backward' then
    	--Your code when it is backward swipe
            --You can change scene for example if you want
    	else
    	--Your code when it is forward swipe
            --You can change scene for example if you want
    	end
    end
     
    local gest = Gestures.new({
        debug = true,
        draw = false,
        drawColor = 0xff0000,
        drawWidth = 5,
        autoTrack = true,
        scope = self,
        allowRotation = false,
        inverseShape = false,
        points = 33
    })
     
    gest:addGesture('Forward', {
        {x = 0, y = 0},
        {x = 0, y = 50}
     
    }, callback)
     
     
    gest:addGesture('Backward', {
       {x = 50, y = 0},
        {x = 0, y = 0}
    }, callback)
  • edited December 2017
    Thank you everyone for your responses!
    I added the Gesture.lua file to my project and added in the above code to my main.lua.
    I added in a
    print("swiped forward")
    after the else in
    if name == 'Backward' then
    and for some reason it always just prints "swiped forward" even when I'm just touching the screen/tapping.
    Did I do something wrong?
    Thanks!
  • simple method
    function LevelSelectScene:onMouseDown(event)
     
     startX = event.x
     
     event:stopPropagation()
    end
     
    function LevelSelectScene:onMouseUp(event)
     
    endX = event.x
     
    if endX- startX > 100 then
     
      print("Forward")
    end
     
    end
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • Thank you, but (and I apologize again if this is a stupid question) I changed LevelSelectScene to stage (assuming that was the right thing to do because I don't have anything called that in my game) and nothing happens.
    I know I'm missing something, if someone could point me in the right direction I would really appreciate it!!
    Thanks so much!

    PS: I'm not using the swipe to change scenes or whatever, I'm just using it to activate a "boost" on my character... if that matters at all...?
  • @MidnightCoffee
    listeners added?

    stage:addEventListener(Event.MOUSE_DOWN, self.onMouseDown, self)
    stage:addEventListener(Event.MOUSE_UP, self.onMouseUp, self)
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • Okay, so now I get an error: "attempt to index global 'self' (a nil value)"
    My code is as follows:
    -- ///////// Swipe Events //////////
    function stage:onMouseDown(event)
     
     startX = event.x
     
     event:stopPropagation()
    end
     
    function stage:onMouseUp(event)
     
    endX = event.x
     
    if endX- startX > 100 then
     
      print("Forward")
    end
     
    end
     
    stage:addEventListener(Event.MOUSE_DOWN, self.onMouseDown, self)
    stage:addEventListener(Event.MOUSE_UP, self.onMouseUp, self)
    Thank you so much for your help! I know I'm making some stupid mistake, but I can't seem to figure it out...
  • antixantix Member
    edited December 2017
    Try this instead..
    -- ///////// Swipe Events //////////
    function onMouseDown(event)
     
     startX = event.x
     
     event:stopPropagation()
    end
     
    function onMouseUp(event)
     
    endX = event.x
     
    if endX- startX > 100 then
     
      print("Right")
    end
     
    end
     
    stage:addEventListener(Event.MOUSE_DOWN, onMouseDown)
    stage:addEventListener(Event.MOUSE_UP, onMouseUp)
    You need to learn about the whole self thingy. self is used within classes to refer to the particular instance of a class. Maybe this tiny example might serve to help..
    Thing = Core.class()
     
    function Thing:init()
      self.name = "thing" -- this things name
      print(self.name .. " created")
    end
     
    function Thing:update()
      print(self.name .. " updated")
    end
     
    local myThing = Thing.new() -- make a new instance of thing
    myThing:update() -- will print the things name
    I need to improve my skills at explaining stuff I think ;)
  • edited December 2017
    Got it working! Thanks so much! I really appreciate it!

    And thanks for the mini lesson! New to Gideros so that was really helpful!
  • @antix, in your example the addEventListeners should not have self.*** but only ***.

    Likes: antix

    +1 -1 (+1 / -0 )Share on Facebook
  • @keszegh, whoops, you are totally right, corrected ;)
Sign In or Register to comment.