Jump to content

  • Log In with Google      Sign In   
  • Create Account

#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