On Screen Joystick (sprite boundries)

Get help using Construct 2

Post » Tue May 15, 2012 5:19 am

I am trying to keep a small sprite bound within a larger sprite and these sprites are placed on a no scrolling layer.

I am trying to emulate a joystick control on screen.

So far no combination of options I have tried have seemed to work and I see no way to keep the small sprite within the bounds of the larger sprite.

Both sprites are circles.
B
3
Posts: 4
Reputation: 308

Post » Tue May 15, 2012 6:11 am

This, in terms of maths, is called clamping. I checked in the math library that construct has, but there was no clamp function. So I made one quickly out of events.

Here is a capx

Here is the demo.

That being said, this could be a very simple modification of the DragDrop Behaviour.brockatkinson2012-05-15 06:11:40
B
14
S
1
G
2
Posts: 85
Reputation: 2,810

Post » Tue May 15, 2012 3:16 pm

Check out this thread:
http://www.scirra.com/forum/limit-drag-to-another-sprites-image-area_topic52025.html

BTW there is a clamp function. It's under 'Values' rather than 'Math'.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Wed May 16, 2012 2:25 am

Thanks for the replies and tips. Nice to find an active community. Will take a look at both items.
B
3
Posts: 4
Reputation: 308

Post » Thu Jun 07, 2012 4:21 am

I want to expand on this and I have to be missing something completely obvious or things I have forgotten from math.

Similar to pointing the player in the direction of the mouse, I want the player to rotate based on the rotation of the joystick. So if the joystick is rotated left the player should rotate left and vice versa.

Setting the rotation using the X, Y coords or angles doesn't do it, using match to get the coords didn't do it and I think I am overlooking something.
B
3
Posts: 4
Reputation: 308

Post » Thu Jun 07, 2012 5:36 am

Not sure that "rotate" is really what you have done with your joystick sprite ... doing a circle like move changing X/Y is not rotate ... there is no rotate "left" in C2 but a rotate "counterclockwise" ... so pointing down make turn toward "->" when counterclockwise and "<-" if pointing up ! ... if a perfect circle is rotate there is no visible change on screen this is like turning a button. So perhaps you succeed making angle of player sprite the same as joystick sprite but is just that joystick sprite angle don't change.

Draw a little arrow pointing right on your joystick sprite ... if this arrow always pointing right when "rotate" ... it's not "rotate" and so angle don't change !

Conclusion : use "joystick : set angle toward position(Mouse.X,Mouse.Y)" to make joystick "looking" the mouse and then give to the player the same angle "player : set angle joystick.angle". Be sure before testing having both the joystick and the player pointing right when having angle property set to 0 (draw a "->" before on them if needed). naelian2012-06-07 07:32:10
B
16
S
5
G
3
Posts: 298
Reputation: 5,240

Post » Fri Jun 08, 2012 4:49 am

I have tried using the angle option to no avail, setting the X, Y coords, and various other combinations, none seem to work as I expected.

Let me explain it a different way, think of the joystick as a compass, so when I press the pad to go East, I want the player to point East, when I press the pad to go South, I want the player to point South.

That might explain it better than saying "rotate."
B
3
Posts: 4
Reputation: 308

Post » Fri Jun 08, 2012 9:49 am

Check here-

Linkchrisbrobs2012-06-08 09:52:36
B
19
S
6
G
7
Posts: 1,206
Reputation: 7,300


Return to How do I....?

Who is online

Users browsing this forum: Megavolt, selaus and 0 guests