Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  Only Clicking Once  (Read 188 times)
0 Members and 1 Guest are viewing this topic.
Offline Genius Coder

Junior Member


Medals: 1
Exp: 4 years



« Posted 2014-02-08 15:08:19 »

I have created a menu that could be naviagted with the keys perfecty. However, when I try to implement a mouse supported menu it doesnt seem to work as the click lasts two long no matter how quick you think you did it and so the menu navigates too far away. The code shown below contains the problem, clicking new game in state 1 will go strate to state 8?!

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  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
public void mouseReleased(MouseEvent e) {
      if ( e.getButton() == MouseEvent.BUTTON1) {
         if (menuState==1) {menuState = 5;}
         if (menuState==2) {menuState = 5;}
         if (menuState==3) {menuState = 5;}
         if (menuState==4) {menuState = 5;}
         if (menuState==5) {menuState = 8;}
      }
   }
   public void updateMouseForMenu() {
      if (menuState == 1 || menuState == 2 || menuState == 3 || menuState == 4) {
         if (instantMsx > 90 && instantMsx < 200) {
            if (instantMsy > 300 && instantMsy < 330) {
               menuState = 1;
            }
         }
         if (instantMsx > 90 && instantMsx < 200) {
            if (instantMsy > 330 && instantMsy < 360) {
               menuState = 2;
            }
         }
         if (instantMsx > 90 && instantMsx < 200) {
            if (instantMsy > 360 && instantMsy < 390) {
               menuState = 3;
            }
         }
         if (instantMsx > 90 && instantMsx < 200) {
            if (instantMsy > 390 && instantMsy < 420) {
               menuState = 4;
            }
         }
      }
     
     
      if (menuState == 5 || menuState == 6 || menuState == 7) {
         if (instantMsx > 90 && instantMsx < 200) {
            if (instantMsy > 300 && instantMsy < 330) {
               menuState = 5;
            }
         }
         if (instantMsx > 90 && instantMsx < 200) {
            if (instantMsy > 330 && instantMsy < 360) {
               menuState = 6;
            }
         }
         if (instantMsx > 90 && instantMsx < 200) {
            if (instantMsy > 360 && instantMsy < 390) {
               menuState = 7;
            }
         }
      }
   }


I love making games...
Offline Dxu1994
« Reply #1 - Posted 2014-02-08 15:18:25 »

Them magic numbers...

Also no shit every time your mouseReleased method is called it will go straight to state 8.

You set menuState to 5 and then check if it's 5 then set it to 8 so it will always be 8.

To fix:

1  
2  
3  
4  
5  
6  
7  
8  
9  
public void mouseReleased(MouseEvent e) {
      if ( e.getButton() == MouseEvent.BUTTON1) {
         if (menuState==1) {menuState = 5;}
         else if (menuState==2) {menuState = 5;}
         else if (menuState==3) {menuState = 5;}
         else if (menuState==4) {menuState = 5;}
         else if (menuState==5) {menuState = 8;}
      }
   }

Offline Genius Coder

Junior Member


Medals: 1
Exp: 4 years



« Reply #2 - Posted 2014-02-08 15:25:47 »

Them magic numbers...

Also no shit every time your mouseReleased method is called it will go straight to state 8.

You set menuState to 5 and then check if it's 5 then set it to 8 so it will always be 8.

To fix:

1  
2  
3  
4  
5  
6  
7  
8  
9  
public void mouseReleased(MouseEvent e) {
      if ( e.getButton() == MouseEvent.BUTTON1) {
         if (menuState==1) {menuState = 5;}
         else if (menuState==2) {menuState = 5;}
         else if (menuState==3) {menuState = 5;}
         else if (menuState==4) {menuState = 5;}
         else if (menuState==5) {menuState = 8;}
      }
   }


Hahaha yeah man that fixed it, wow im retarded :/ I have been programming for so long I cant see the stupid stuff like that yet I can fix some very complex code problems :/

I love making games...
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (29 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (78 views)
2014-09-10 06:39:09

Tekkerue (38 views)
2014-09-09 02:24:56

mitcheeb (58 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (30 views)
2014-09-07 01:12:14

Longarmx (35 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!