How do I move left and right based on touch location?

Just started using Construct 2? Post your questions here

Post » Wed Apr 16, 2014 8:19 am

How do I move left and right based on touch location?

For example, if the player touches the screen on the left side, I'd like to move left and vice versa.

I am not sure how to compare the current view's center x value to the touch position's x value (which I know is Touch.X).

Thanks in advance for any help. :D
B
3
Posts: 9
Reputation: 193

Post » Wed Apr 16, 2014 11:01 am

Hi Leespiker IMHO, let's say you have layout size of 800 width and 300 height. add an empty sprite and set size to 400 (half size of the layout width) and height of 300. name it "leftside" and then duplicate it and name the other "Rightside". then you can add events like: ON "leftside" touched ==> action: "player" move left
ImageImageImageImageImage
B
56
S
15
G
5
Posts: 852
Reputation: 11,446

Post » Wed Apr 16, 2014 8:23 pm

Naji wrote:Hi Leespiker IMHO, let's say you have layout size of 800 width and 300 height. add an empty sprite and set size to 400 (half size of the layout width) and height of 300. name it "leftside" and then duplicate it and name the other "Rightside". then you can add events like: ON "leftside" touched ==> action: "player" move left


Right, I thought of that, but if the current view is not the whole screen (like on a mobile app), then if you were on the left side of the screen and clicked/touched, then you would move left even though you clicked on the right side of the "current view screen" since the player cannot see the entire map, just a small portion of it.
B
3
Posts: 9
Reputation: 193

Post » Wed Apr 16, 2014 8:27 pm

I could check if the touch position's x value is greater than or less than the player's current x value, but how would I go about checking that if statement?
B
3
Posts: 9
Reputation: 193

Post » Wed Apr 16, 2014 8:41 pm

You can compare Touch.X to scrollx.
touchLeftRight.PNG
You do not have the required permissions to view the files attached to this post.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,670

Post » Wed Apr 16, 2014 8:43 pm

I would make a "pointer" graphic for debug purposes and compare it's position. Make it invisible eventually, but It's always good to know where the touch is. It might be a bad idea, but that how I've done it in the past.
B
35
S
9
G
3
Posts: 493
Reputation: 4,092

Post » Thu Apr 17, 2014 1:09 am

ramones wrote:You can compare Touch.X to scrollx.
touchLeftRight.PNG


Thank you. This is exactly what I needed.

I did the following:

Image

Would you happen to know how to tell if 2 touches are currently being made?

EDIT: Figured it out on my own. :D
B
3
Posts: 9
Reputation: 193

Post » Fri Apr 18, 2014 10:17 am

Leespiker good for you that is how one learns
B
256
S
39
G
15
Posts: 1,983
Reputation: 41,036


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests