Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


#Actualphirekid718

Posted 01 July 2013 - 08:55 PM

I am trying to implement a joystick in cocos2d-x. The idea is to allow the user to slide a circle within a larger circle so the direction of the slide controls the direction the character moves. If there is a better way to do this please let me know but so far my code looks something like this:

 

if(joystick.x < xMin)
         joystick.x = xMin;
     if(joystick.x > xMax)
         joystick.x = xMax;
     if(joystick.x < yMin)
         joystick.x = yMin;
     if(joystick.x > yMax)
        joystick.x = yMax;

 

The joystick in this code represents a circular sprite that the user can slide around to control the character. But as you can see, the code confines the sprite so that it stays within a box formed by the sides xMin,xMax,yMin and yMax. I don't want that. I want to confine the sprite within a larger circle. How can I do this? Please and thank you.


#1phirekid718

Posted 01 July 2013 - 08:50 PM

I am trying to implement a joystick in cocos2d-x. The idea is to allow the user to slide a circle within a larger circle so the direction of the slide controls the direction the character moves. If there is a better way to do this please let me know but so far my code looks something like this:

if(joystick.x < xMin)
         joystick.x = xMin;
     if(joystick.x > xMax)
         joystick.x = xMax;
     if(joystick.x < yMin)
         joystick.x = yMin;
     if(joystick.x > yMax)
        joystick.x = yMax;


PARTNERS