How do I limit movement of sprite object to a box

Get help using Construct 2

Post » Thu Dec 03, 2015 3:01 am

https://www.dropbox.com/s/1506ldu1eh99f ... .capx?dl=0

What is the best way to keep the touch pad within the limits of the green box? Currently the stick is able to move all over the screen, howver I would like to limit it's movement to the green box area.
B
5
S
1
Posts: 36
Reputation: 451

Post » Thu Dec 03, 2015 3:19 am

Use the clamp function to limit the position of sangStick. For example, every tick you could set the position of sangStick to:

X: clamp(sangStick.X, boundary.BBoxLeft, boundary.BBoxRight)
Y: clamp(sangStick.Y, boundary.BBoxTop, boundary.BBoxBottom)
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,126

Post » Thu Dec 03, 2015 9:59 am

You might be interested in this Touchstick example:

Thumbstick
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 » Thu Dec 03, 2015 2:58 pm

Thanks :) both work perfectly. Decided to use a combination of both and worked really well. :)
B
5
S
1
Posts: 36
Reputation: 451


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests