On Screen Joystick (sprite boundries)

0 favourites
  • 8 posts
From the Asset Store
A smart joystick plugin, perfect for all mobile games.
  • 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.

  • 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.

  • 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'.

  • Thanks for the replies and tips. Nice to find an active community. Will take a look at both items.

  • 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.

  • 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).

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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."

  • Check here-

    Link

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)