How do I use swipes to move an object

Get help using Construct 2

Post » Tue Aug 25, 2015 7:21 pm

Hi,

I'm trying to figure out how can i use swipe movements to move an object (ball) in any direction of my layout. I don't want to use buttons or the keyboard for it, only swipes (as it intended to be for touch screen devices). This object also should have different velocities, depending on the swipes velocity it is given to it. And the movement has to gradually decrease until it stops or another swipe make it move again in any other direction. The game works in a top down view, so i have already remove gravity from the object, and finished almost all the game layout. The game is working but i'm using the arrows to move the ball. I would like to know how to do this using swipes. I've already searched the tutorials here, on Youtube, and on the Construct manual, but i wasn't able to make it work. If someone has a example or something that can ilustrate this kind of behavior or how to do it, it will be pretty much appreciated. Thanks!
B
14
S
5
Posts: 110
Reputation: 1,338

Post » Tue Aug 25, 2015 9:34 pm

B
98
S
34
G
20
Posts: 438
Reputation: 17,825

Post » Tue Aug 25, 2015 11:36 pm

AllanR,

Yes! Thank you very much!

On my layout i got some solid objects, but the ball just ignore any solid object in its way. I wish it could bounce on it, or depending on the veloccity maybe stop moving. May you help me with that, please?
B
14
S
5
Posts: 110
Reputation: 1,338

Post » Wed Aug 26, 2015 2:16 am

@artbava I added Physics to the ball and objects (that was the easiest way to make the ball bounce off of things). You can download the capx from the link above again to get the updated version.

Blue objects can not move at all, green objects are dense and don't move much. Yellow objects are light and move easily...

You will need to add Physics to any objects in your game that you want the ball to interact with. Since you are doing top-down, World Gravity needs to be 0. Your objects don't need the solid behavior (just Physics). Update objects Density, Linear Dampening, or other properties to make the ball interact the way you want...

It runs well on my iPhone.
B
98
S
34
G
20
Posts: 438
Reputation: 17,825

Post » Wed Aug 26, 2015 5:44 am

AllanR,

You are awesome! Really appreciated your help! Thank you again! I will try it and let you know how i'm doing.

Best wishes!!!
B
14
S
5
Posts: 110
Reputation: 1,338

Post » Wed Aug 26, 2015 2:41 pm

AllanR,

I've noticed that in the first project code you've used custom movement, but not in the second one. Despite not using it, the ball still have custom movement behavior on its behavior list (probably from the previous project). But comparing them (codes and results) the first one has a progressive deceleration movement, which the second one doesn't. This deceleration is set by using custom movement speed*0.98 to ball, am i right? So, should i preserve the custom movement behavior and code to gradually decelerate the ball being able to fine tuning it according to my needs, or can i get a similar result without it? I did not notice the same effect on the ball deceleration just changing Linear damping or elasticity. Any tip or advice?
B
14
S
5
Posts: 110
Reputation: 1,338

Post » Wed Aug 26, 2015 8:55 pm

@artbava no, you should remove the custom movement (I forgot to). The second version uses Physics to move the ball, and physics slows down the ball using friction and linear damping, so there is no need to manually decelerate the ball.

the elasticity sets how bouncy the ball is. Linear Damping should be the main way to slow the ball down - I had it at 0.2 to keep it moving a long time. Try something like 0.9 to slow it down at a faster rate (and/or apply less acceleration to the ball).
B
98
S
34
G
20
Posts: 438
Reputation: 17,825

Post » Thu Aug 27, 2015 2:49 pm

AllanR,

I'm very grateful for your help. I spent some time messing with some variables and finally managed to get the result I wanted. In the end I learned a lot from it. You have been an excellent teacher, and I apologize for my inexperience, but as I said, now I feel a bit more ready for new discoveries. As soon as I finish the game, I'll send you a copy and your name will be in the credits as an important contributor. I know this does not mean much, because I do not know if you will like the game (or other people will), but know that your help meant a lot to me. Many thanks once again!

You should write a tutorial, you are very good with that! If you have any material posted on some blog or on the Internet I would like to see it.

All the best for you!
B
14
S
5
Posts: 110
Reputation: 1,338


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests