I have 2 circular buttons spinning around in a circle and i need the program to be able to recognize that i have clicked within the circles, one of the buttons is for start one is for quiting.
Here are the declared relevant variables at the top of my code
double angleStart=1.5*pi;
double angleQuit=0.5*pi;
int radius=120;
int centerX=300;
int centerY=160;
float startPosX = (float) (centerX + Math.sin(angleStart)*radius);
float startPosY = (float) (centerY + Math.cos(angleStart)*radius);
float quitPosX = (float) (centerX + Math.sin(angleQuit)*radius);
float quitPosY = (float) (centerY + Math.cos(angleQuit)*radius);
the images/buttons are drawn at startPosX/Y and quitPosX/Y
Here is the code that makes the buttons spin
int posX = Mouse.getX();
int posY = Mouse.getY();
double constant=0.002*pi;
startPosX = (float) (centerX + Math.sin(angleStart)*radius);
startPosY = (float) (centerY + Math.cos(angleStart)*radius);
quitPosX = (float) (centerX + Math.sin(angleQuit)*radius);
quitPosY = (float) (centerY + Math.cos(angleQuit)*radius);
angleStart+=constant;
angleQuit+=constant;
if (angleStart>=2*pi){
angleStart-=2*pi;
}
if (angleQuit>=2*pi){
angleQuit-=2*pi;
}
Also as you can see PosX and PosY are the mouse coords
Now finally here is the code that decides if the buttons have been clicked or not
//start button
float startXDist=posX-(startPosX+50);
float startYDist=posY-(startPosY+50);
float startDist=(float) Math.sqrt((startXDist*startXDist)+(startYDist*startYDist));
if(startDist<=50){
if(Mouse.isButtonDown(0)){
sbg.enterState(1);
}
}
//quit button
float quitXDist=posX-(quitPosX+50);
float quitYDist=posY-(quitPosY+50);
float quitDist=(float) Math.sqrt((quitXDist*quitXDist)+(quitYDist*quitYDist));
if(quitDist<=50){
if(Mouse.isButtonDown(0)){
System.exit(0);
}
}
When run nothing (normally) happens when i click the buttons but if i spam my mouse randomly all over the screen sometimes is hits an area which is perceived by the program as me clicking the button, thanks for the help in advance
extra note the +50's are in there because the button has a radius of 50px
im afraid i cant post images yet but heres a link to a screenshot http://s2.postimg.org/h9ykqpd5l/Capture6.png
also the little bean is a temporary graphic in place until i make one my self