Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Is there a way to detect a diagonal swipe using Gestures in Gideros? — Gideros Forum

Is there a way to detect a diagonal swipe using Gestures in Gideros?

AxlFlameAxlFlame Member
edited October 2014 in Game & application design
Hey, guys!

I am trying to create a scene on my game where the player must do a diagonal swipe (bottom left to top right, vice-versa). I'm using the Gestures.lua that @ar2rsawseen created, but I can't make the class recognize only the diagonal swipe...

I'm adding the gesture like this:
	self.gest:addGesture("Cut", {
		{x = 0, y = 0},
		{x = 75, y = 50}
	}, self.callback)
To be honest, I don't understand the class very well, so the points are probably wrong...
Can someone help?

Comments

  • Hi @AxlFlame

    Check this link
    http://giderosmobile.com/forum/discussion/773/scenemanager-and-managing-memory/p1

    Here you're going to find @ndoss 's swipe version (his performance)

    I hope the above serve you something

    Cheers

    Likes: AxlFlame

    +1 -1 (+1 / -0 )Share on Facebook
  • Hey, @HubertRonald!

    I think I don't see the solution I'm looking for on that topic, unfortunately. What I want is to be able to detect a diagonal swipe on the screen (in-game it's gonna be like a sword slash). I don't know how I would implement this other swipe method you're talking about. Can you explain it to me?

    I thought about using @ar2rsawseen 's Gestures.lua, because then I would just need to find out which points would correspond to a diagonal swipe within a given scope.
  • Hello @AxlFlame

    Unfotunately Gestures.lua won't help you for two reasons.

    1) It is meant to detect closest gesture from a set of gestures, so if you only define one gesture, then to any gesture you make, the closest one will be the one you defined

    2) I think there was a bug in single line gestures, that their rotation and direction was not properly taken care off

    About swipe Gestures, I created something like this some time before:
    https://github.com/ar2rsawseen/GiderosCodingEasy/blob/master/GestureEventEasy.lua

    But unfortunately it only handles up, down, left, right swipes, but diagonal swipes can be added in similar manner, all you need is to determine direction, or if you don't care which direction it is, as long as it is diagonal swipe, you can even do something as:
    --can be a swipe event
    if math.abs(e.touch.x - touches[e.touch.id].x) <= sets.swipeDisperse and
    	math.abs(e.touch.y - touches[e.touch.id].y) > sets.swipeDistance then --vertical
    	e.swipeDistance = e.touch.y - touches[e.touch.id].y
    	if e.touch.y - touches[e.touch.id].y > 0 then --down
    		dispatchSwipeEvent(Event.SWIPE_DOWN, e)
    	else --up
    		dispatchSwipeEvent(Event.SWIPE_UP, e)
    	end
    elseif math.abs(e.touch.x - touches[e.touch.id].x) > sets.swipeDistance and
    	math.abs(e.touch.y - touches[e.touch.id].y) <= sets.swipeDisperse then --horizontal
    	e.swipeDistance = e.touch.x - touches[e.touch.id].x
    	if e.touch.x - touches[e.touch.id].x > 0 then --right
    		dispatchSwipeEvent(Event.SWIPE_RIGHT, e)
    	else --left
    		dispatchSwipeEvent(Event.SWIPE_LEFT, e)
    	end
    else -- if it is not vertical nor horizontal swipe
    	local dx = e.touch.x - touches[e.touch.id].x
    	local dy = e.touch.y - touches[e.touch.id].y
    	--check distance of the swipe
    	if math.sqrt(dx*dx + dy*dy) > sets.swipeDistance then
    		dispatchSwipeEvent("swipeDiagonal", e)
    	end
    end

    Likes: AxlFlame

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.