Move a sprite with a touch gesture on one axis only?

Get help using Construct 2

Post » Fri Sep 26, 2014 4:21 am

Here's what I need to accomplish:

I need to drag a sprite along the x or y axis according to the direction the user swipes, but once the sprite starts to move, it can only move on a single axis until the next touch. So no matter the direction of the swipe, whether it's diagonally or on the other axis, only the original axis registers until the user ends the touch and touches again.

I can get the sprite to follow the touch, but I need them to move either horizontally or vertically. I'm pretty sure I need to acquire the direction of the swipe before anything else, but I'm completely stumped on how to do that.
B
10
S
1
Posts: 67
Reputation: 909

Post » Fri Sep 26, 2014 4:59 am

I haven't fooled with touch much but I would start with looking at the fruit slicer tutorial, seems its slice might be useful.

it uses the Touch on-any-touch-start set action1: variableX Touch.X action2: variableY Touch.Y
then uses those to
Set angle to angle (variableX, variableY, Touch.X, Touch.Y) degrees

this would give you your angle swiped at least.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
70
S
19
G
8
Posts: 639
Reputation: 9,674

Post » Fri Sep 26, 2014 6:53 am

touch.AngleAt would give you the angle of your touch movement..

round this to 0,90,180,270 and you only have the straight horizontal and vertical movement..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Sep 26, 2014 8:02 pm

Thank you so much you guys!!! @chrisinfinger I was able to setup a visual debugging system with that tutorial, which is super helpful. @LittleStain I ended up using Touch.AngleAt(Touch.TouchIndex) to get the angle and it works perfectly! :lol:
B
10
S
1
Posts: 67
Reputation: 909


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo and 27 guests