How can I do to know where the user touched?

Get help using Construct 2

Post » Wed Oct 07, 2015 7:27 pm

I need to know where the user touched in the screen to move a character horizontally. For example: my screen is 1280 x 720 px. If the touch was in the first half of the screen (0, 639) the character moves to left and if the touch happened in the second half of the screen, the character moves to right. Is it possible?

Thanks in advance for any help!
B
74
S
13
G
4
Posts: 1,005
Reputation: 8,058

Post » Wed Oct 07, 2015 7:34 pm

system compare two values : touch.x < 640
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 » Wed Oct 07, 2015 7:38 pm

Thank you, @LittleStain
B
74
S
13
G
4
Posts: 1,005
Reputation: 8,058

Post » Thu Oct 08, 2015 12:17 am

If you would rather not make on screen controls for movement. You could compare the Touch.X and Touch.Y with the PLayer.X and Y.

If touch.X>Player.X---Move Right

If touch.X<Player.X---Move to the left

If touch.Y>Player.Y---Move Up

If touch.Y<Player.Y---Move Down

Compare the X and Y separately, and the diagonal movements should be automatic. This is awesome for people with only 8 direction sprites. They do not rotate to the sprite so they keep their proper alignment.

You can also have them rotate and move towards the mouse, but that really looks crappy.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Thu Oct 08, 2015 9:57 am

Thanks @jojoe

I used this same solution. It is better than being restricted to the screen size
B
74
S
13
G
4
Posts: 1,005
Reputation: 8,058


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, dop2000, tarek2 and 43 guests