Page 1 of 1

Swipe for movement

PostPosted: Wed 16 May 2018, 18:46
by MeX1Co
Hi... I have been trying for a week and I still cant figure it out...

What I want basically is to swipe on the left half of the screen of the mobile device and according to the direction of the swipe to apply a force on the character...

I tried to modify the multitouch example (I use the gdevelop 4 version) and i gave a condition of X < 400 to specify the left half of the screen, and it works... I can see the marker only when i touch on the left side but i cant figure out how to use the direction...

Thank you in advance for your time...

Re: Swipe for movement

PostPosted: Wed 16 May 2018, 20:18
by Lizard-13
You should keep track the touch position, saving it in variables, and then get the delta position (swipe) at some point:
Code: Select allVariable "swipeX" = TouchX() - Variable(touchStartX)

For example when a new touch is detected, save the X and Y position in two variables "touchStartX" and "touchStartY", and when the touch is released get the deltas as I did above, then you can get the swipe angle as:
Code: Select allatan2(Variable(swipeY), Variable(swipeX))

And the swipe length with:
Code: Select allsqrt(pow(Variable(swipeX), 2) + pow(Variable(swipeY), 2))

:)

The only problem you can face is in case you can't get the touch position on release, if you can't get it you'll have to save the touch current position every frame in other two extra variables, and use these variables instead TouchX() to get the delta "swipeX" for example.

Re: Swipe for movement

PostPosted: Fri 18 May 2018, 14:38
by MeX1Co
Lizard-13 you are awesome...

So to test once more your awesomeness how would you go about making it so that when you swipe on the left side of the screen you get the swipe but while you tap on the right side you get an action???

I have the following for now...

q01.JPG
q01.JPG (46.08 KiB) Viewed 398 times


and while the left part is working perfectly, when i tap on the right side the StarGlow variable goes to 1 for one moment and it immediately goes back to zero... any thoughts???

Re: Swipe for movement

PostPosted: Fri 18 May 2018, 14:55
by MeX1Co
scratch that... I found the problem... since it is a web game i wanted it to have both keyboard and touch controls...

so i had that when space is pressed the StarGlow variable goes to 1 and when it is not pressed it goes back to 0.... I changed it to when space is released and it works now...

You can check the motion test here... on keyboard you can use the arrows to move and space to glow, and on a touch screen swipe on the left side to determine the direction of the movement and tap to the right side to glow...

http://meviportal.esy.es/sm/06/