Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (744)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (825)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  i got a problem with buttons  (Read 1303 times)
0 Members and 1 Guest are viewing this topic.
Offline VIrtueeL
« Posted 2014-03-10 12:24:29 »

well i created an class called ButtonState that has 2 enums UP and DOWN here is class
btw dont know where to post this
1  
2  
3  
4  
5  
6  
      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
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
      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]
      
1  
2  
3  
4  
5  
6  
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
   
1  
2  
3  
4  
5  
6  
7  
8  
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
         
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
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
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
      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;
      }

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline Grunnt

JGO Kernel


Medals: 143
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #1 - Posted 2014-03-10 12:28:22 »

Please use the
1  
code
tags to clarify where your code actually is.

Offline VIrtueeL
« Reply #2 - Posted 2014-03-10 12:29:33 »

just saw you can do that ^^ its fixed

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #3 - Posted 2014-03-10 12:34:08 »

1  
public ButtonState buttonState = ButtonState.DOWN;

Why are all OpenGL tutorials written in Brainf**k?
Offline VIrtueeL
« Reply #4 - Posted 2014-03-10 12:35:02 »

sy will post it

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline Grunnt

JGO Kernel


Medals: 143
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #5 - Posted 2014-03-10 12:38:12 »

What does the GameEngine.rec_mouse thing do? I would expect a mouse position to be a point, not a rectangle. That could be a reason (i.e. a rectangle can overlap multiple buttons, while a point cannot).

Also, are you creating a new button every time you check whether the button is clicked?

Finally, are you actually checking for a mouse click? It seems you only check for mouseover.

Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #6 - Posted 2014-03-10 12:39:59 »

@VirtueeL You're such a good troll by the way.
Oh I'm oozing sarcasm today.

Why are all OpenGL tutorials written in Brainf**k?
Offline VIrtueeL
« Reply #7 - Posted 2014-03-10 12:44:58 »

ok here

and rec_mouse is the mouse currents moving pos and if its over the button set the state to down and if press do what ever it says


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
   @Override
   public void mousePressed(MouseEvent e) {
      //MAIN MENU
      if(State.State == State.MENU_MENU){
         if(MainMenu.SinglePlayer.buttonState.equals(ButtonState.DOWN)){
            State.setState(State.SINGLEPLAYERMENU);
            Assets.playSound("back1.wav");
         }
         if(MainMenu.Multiplayer.buttonState.equals(ButtonState.DOWN)){
            Sys.sendSytemMessage("Working Great!");
            Assets.playSound("warningerror.wav");
         }
         if(MainMenu.Quit.buttonState.equals(ButtonState.DOWN)){
            System.exit(1);
         }
      }
      if(State.State == State.SINGLEPLAYERMENU){
         if(SinglePlayerMenu.ok.buttonState.equals(ButtonState.DOWN)){
            //MAKE SO YOU CAN SWITCH STATE
               State.setState(State.SINGLEPLAYERGAME);
               Assets.playSound("back1.wav");
         }
      }
   }


that is when i check for button pressed

this is how i create one

1  
2  
public static Button ok;
SinglePlayerMenu.ok = new Button(230+170*3+50, 520, 100 , 50,"ok!",ButtonState.DOWN);

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline VIrtueeL
« Reply #8 - Posted 2014-03-10 12:48:51 »

btw if i check when its moving over the button and then change the state its working some how as i want it but i want the player
to press it

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline VIrtueeL
« Reply #9 - Posted 2014-03-10 12:57:21 »

well its solved if i create diffrent booleans for etch button =/ does not work if just create 1

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Pages: [1]
  ignore  |  Print  
 
 

 
Ecumene (149 views)
2017-09-30 02:57:34

theagentd (222 views)
2017-09-26 18:23:31

cybrmynd (301 views)
2017-08-02 12:28:51

cybrmynd (288 views)
2017-08-02 12:19:43

cybrmynd (297 views)
2017-08-02 12:18:09

Sralse (291 views)
2017-07-25 17:13:48

Archive (978 views)
2017-04-27 17:45:51

buddyBro (1102 views)
2017-04-05 03:38:00

CopyableCougar4 (1678 views)
2017-03-24 15:39:42

theagentd (1430 views)
2017-03-24 15:32:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!