How do I Swipe

Get help using Construct 2

Post » Thu Oct 20, 2016 8:57 am

Hi,

I'm searching for a lot of time how to control a character with a swipe touch.
Not only in 8 direction, but exactly as I swipe, or split the screen into two sides, horizontal and vertical.
Is there a tutorial for this, I prefer video.

Thanks,
Idan
B
5
S
2
Posts: 5
Reputation: 435

Post » Thu Oct 20, 2016 3:00 pm

If it's sufficient for you to move your character as soon as the swipe ends (the user lifts his finger), you use this solution:

- add the "Touch" object (obviously)

- add two global variables "InitialX", "InitialY","CurrentX", "CurrentY" and "TouchAngle", all numbers

- add an event "On touch start" with the following actions in it:
--> Set InitialX to Touch.AbsoluteX (or .X, if that suits your project better)
--> Set InitialY to Touch.AbsoluteY (or .Y)

- add a condition "Is touching" with the following actions in it:
--> Set CurrentX to Touch.AbsoluteX (or .X)
--> Set CurrentY to Touch.AbsoluteY (or .Y)

- add an event "On touch end" with the following actions in it:
--> Set TouchAngle to "angle(InitialX,InitialY,CurrentX,CurrentY)"


Now the swipe direction is stored in the TouchAngle variable.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091


Return to How do I....?

Who is online

Users browsing this forum: dop2000, irina and 8 guests