well i created an class called ButtonState that has 2 enums UP and DOWN here is class
btw dont know where to post this
DOWN,UP;
public static ButtonState ButtonState = null;
public static void SetBState(ButtonState state){
ButtonState = state;
}
then i created button class
that allows me to create alot buttons with same things
public ButtonState buttonState = ButtonState.DOWN;
public int xTile;
public int yTile;
public int width;
public int height;
public String text = "";
public int playsound = 0;
public Button(int xTile, int yTile,int width, int height ,String text, ButtonState buttonState) {
this.xTile = xTile;
this.yTile = yTile;
this.width = width;
this.height = height;
this.text = text;
this.buttonState = buttonState;
}
public Rectangle getBounds(){
return new Rectangle(xTile , yTile - 25, width , height);
}
and this is where i check if the custom mouse is collidiong with em [btw works]
Assets.CreateButton120x35(ok,g2d, ok.buttonState, ok.xTile, ok.yTile, ok.width, ok.height, ok.text);
if(GameEngine.rec_mouse.intersects(ok.getBounds())){
ok.buttonState = ButtonState.DOWN;
}else{
ok.buttonState = ButtonState.UP;
}
this is how i set the states
public static void setState(State state){
State = state;
System.out.println(state+"");
}
public static void ClearState(){
State = null;
}
public static State State = null;
this is where i check if its pressed
if(MainMenu.SinglePlayer.buttonState.equals(ButtonState.DOWN)){
State.setState(State.SINGLEPLAYERMENU);
Assets.playSound("back1.wav");
}
if(SinglePlayerMenu.ok.buttonState.equals(ButtonState.DOWN)){
//MAKE SO YOU CAN SWITCH STATE
State.setState(State.SINGLEPLAYERGAME);
Assets.playSound("back1.wav");
}
ok so here is the problem when i press single player it changes the state to SINGLEPLAYERMENU
then to SINGLEPLAYERGAME diractly why?
SinglePlayerMenuClass
Assets.CreateButton120x35(player1,g2d, player1.buttonState, player1.xTile, player1.yTile, player1.width, player1.height, player1.text);
if(GameEngine.rec_mouse.intersects(player1.getBounds())){
player1.buttonState = ButtonState.DOWN;
}else{
player1.buttonState = ButtonState.UP;
}
Assets.CreateButton120x35(player2,g2d, player2.buttonState, player2.xTile, player2.yTile, player2.width, player2.height, player2.text);
if(GameEngine.rec_mouse.intersects(player2.getBounds())){
player2.buttonState = ButtonState.DOWN;
}else{
player2.buttonState = ButtonState.UP;
}
Assets.CreateButton120x35(player3,g2d, player3.buttonState, player3.xTile, player3.yTile, player3.width, player3.height, player3.text);
if(GameEngine.rec_mouse.intersects(player3.getBounds())){
player3.buttonState = ButtonState.DOWN;
}else{
player3.buttonState = ButtonState.UP;
}
Assets.CreateButton120x35(player4,g2d, player4.buttonState, player4.xTile, player4.yTile, player4.width, player4.height, player4.text);
if(GameEngine.rec_mouse.intersects(player4.getBounds())){
player4.buttonState = ButtonState.DOWN;
}else{
player4.buttonState = ButtonState.UP;
}
Assets.CreateButton120x35(player5,g2d, player5.buttonState, player5.xTile, player5.yTile, player5.width, player5.height, player5.text);
if(GameEngine.rec_mouse.intersects(player5.getBounds())){
player5.buttonState = ButtonState.DOWN;
}else{
player5.buttonState = ButtonState.UP;
}
//THIS BUTTON IS GONA CHANHE STATE WHEN IS PRESSED NOT DIRACTLY
Assets.CreateButton120x35(ok,g2d, ok.buttonState, ok.xTile, ok.yTile, ok.width, ok.height, ok.text);
if(GameEngine.rec_mouse.intersects(ok.getBounds())){
ok.buttonState = ButtonState.DOWN;
}else{
ok.buttonState = ButtonState.UP;
}