Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (529)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: [States] [Networking] [slick2d] Game state is being initialized when not wanted on: 2012-06-14 04:48:10
Ya that fixed it, thank you.
2  Game Development / Newbie & Debugging Questions / Re: [States] [Networking] [slick2d] Game state is being initialized when not wanted on: 2012-06-14 04:43:02
I totally am, I'll adjust it. Sorry I've been programming this non-stop since Monday, think I'm getting sloppy.
3  Game Development / Newbie & Debugging Questions / Re: [States] [Networking] [slick2d] Game state is being initialized when not wanted on: 2012-06-14 01:36:57
Exception in thread "main" java.lang.RuntimeException: No game state registered with the ID: 0
   at org.newdawn.slick.state.StateBasedGame.enterState(StateBasedGame.java:153)
   at org.newdawn.slick.state.StateBasedGame.enterState(StateBasedGame.java:131)
   at CodaClient.<init>(CodaClient.java:22)
   at CodaClient.main(CodaClient.java:27)
4  Game Development / Newbie & Debugging Questions / Re: [States] [Networking] [slick2d] Game state is being initialized when not wanted on: 2012-06-13 17:53:54
And Rebirth, the change to the way I handle the connection info works wonderfully, thank you. But I needed to keep it in the GameState, But I adjusted based on what you said
5  Game Development / Newbie & Debugging Questions / Re: [States] [Networking] [slick2d] Game state is being initialized when not wanted on: 2012-06-13 17:25:13
If I try it that way it throws an error about not having a state with an ID of 0, so they are not initialized at all (I'm assuming), even if I leave the
1  
2  
this.getState(MAINMENUSTATE).init(gameContainer, this);
this.getState(GAMEPLAYSTATE).init(gameContainer, this);

sections in, once the .addstate() code is moved it doesnt work.
6  Game Development / Newbie & Debugging Questions / Re: [States] [Networking] [slick2d] Game state is being initialized when not wanted on: 2012-06-13 09:36:19
Alright ill give that a shot, thank you
7  Game Development / Newbie & Debugging Questions / Re: [States] [Networking] [slick2d] Game state is being initialized when not wanted on: 2012-06-13 09:19:32
Full source is uploaded, and I could try that, but that sounds like a messy workaround, considering that the initStatesList() is meant as a list to declare what to init (or so I thought) and basically SHOULD do the same thing. I probably just messed up something in my declarations that I didn't notice cause I am quite new to the Slick2D lib
8  Game Development / Newbie & Debugging Questions / Re: [States] [Networking] [slick2d] Game state is being initialized when not wanted on: 2012-06-13 09:06:35
I'll post the full source, but the issue is that it's even running that code, I don't need that code until it has the data that I declare earlier in the program. Basically in the menus I get the user to login, then it sends those credentials to the server in the GameState. But on Launch the GameState init() is being run when I dont want to call it until I need it.

Ill post full source code once I copy it to the bin, but would there be a better way to approach something like this?
9  Game Development / Newbie & Debugging Questions / Re: [States] [Networking] [slick2d] Game state is being initialized when not wanted on: 2012-06-13 08:54:33
sorry forgot to put it in, it's there now. Is there anything else that I should include to make this easier? like the gameState init()?
10  Game Development / Newbie & Debugging Questions / [States] [Networking] [slick2d] Game state is being initialized when not wanted on: 2012-06-13 08:48:50
Seems like my game state is being initialized even though I have it commented out in the initStatesList(...) is there a reason for that? I have it initializing network code would that affect the initializing?

the exact error im getting is:
Quote
Unable to get I/O connection to: localhost on port: 1967
Exception in thread "main" java.lang.NullPointerException
   at GameplayState.init(GameplayState.java:136)
   at org.newdawn.slick.state.StateBasedGame.init(StateBasedGame.java:171)
   at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:390)
   at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:314)
   at CodaClient.main(CodaClient.java:33)

but the only connection attempt to localhost is in the game state

Heres my initStatesList:
1  
2  
3  
4  
5  
6  
public void initStatesList(GameContainer gameContainer) throws SlickException {
        this.getState(MAINMENUSTATE).init(gameContainer, this);
        //this.getState(GAMEPLAYSTATE).init(gameContainer, this);
       this.getState(VICTORYSTATE).init(gameContainer, this);
        this.getState(OPTIONSSTATE).init(gameContainer, this);
}


and the states added to the state list:
1  
2  
3  
4  
5  
6  
7  
8  
super("Title");

this.addState(new MainMenuState(MAINMENUSTATE));
this.addState(new GameplayState(GAMEPLAYSTATE));
this.addState(new VictoryState(VICTORYSTATE));
this.addState(new OptionsState(OPTIONSSTATE));

this.enterState(MAINMENUSTATE);


Complete Source Code:
CodaClient.java: http://pastebin.com/SvGnbVXr
MainMenuState.java: http://pastebin.com/W8bBDbn6
GameplayState.java: http://pastebin.com/rXm0kkik
OptionsState.java: http://pastebin.com/wStTBq0L
VictoryState.java: http://pastebin.com/gvUpGJf9

Based on slickBox Tutorial: http://slick.cokeandcode.com/wiki/doku.php?id=02_-_slickblocks

Edit: couldn't get the JGO files to work so I just used pastebin
11  Game Development / Newbie & Debugging Questions / Re: [Slick2d] [input] Keys and mouse firing too fast on: 2012-06-13 04:30:23
That worked, thank you very much
12  Game Development / Newbie & Debugging Questions / [Slick2d] [input] Keys and mouse firing too fast on: 2012-06-13 03:35:10
Hey I'm having an issue were, when clicking on a button or when clicking a key, the key or mouse click fires like 10 responses (restricting my game to 30fps reduces the number to that, without the fps reduction its closer to 100) I'm just wondering how I can maintain that when I click or hit a button, it with only receive one response?

heres some of my input code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
// Play button
if( ( mouseX >= 0 && mouseX <= play_button.getWidth()) && ( mouseY >= 90 && mouseY <= 90 + play_button.getHeight()) ){
   insidePlay = true;
}

if(insidePlay){
   if(playScale < 1.015f)
      playScale += scaleStep * delta;
             
   if ( input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) ){
           if(!isLogin) {
                 tryLogin = true;
              } else {
                 sb.enterState(CodaClient.GAMEPLAYSTATE);
              }
         }
 }else{
        if(playScale > 1.0f)
            playScale -= scaleStep * delta;
 }


EDIT: Sorry if there's another thread with a similar question, I searched threw a few pages but wasn't sure what this exact issue is called, so I didnt find much that helped.
13  Game Development / Newbie & Debugging Questions / Re: Need help swapping between States on: 2012-06-12 05:51:08
FIXED: It didn't have to do with the states at all, it was the in the mouse check, was exiting the display if it was outside every button (which it would be no matter what).
14  Game Development / Newbie & Debugging Questions / Need help swapping between States (FIXED) on: 2012-06-12 05:35:07
Hey, I'm having difficulty figuring out why I cannot swap between 2 different states, the game just crashes after I click the button to make the switch. Was just wondering if someone could give me a hand?

I run the game, click on the high scores button, then the display closes. I was following the SlickBox example http://slick.cokeandcode.com/wiki/doku.php?id=02_-_slickblocks

Sorry about the wall of code, but I really don't know were the issue is.

EDIT: after a bit more debugging it seems to be on the input, when I click anywhere on the screen, it just closes the display, is there anything that could be causing that?

Heres my Main file:
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  
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;
 
/**
 * @author Tyler Matchett
 */

public class CodaClient extends StateBasedGame {
 
   public static final int MAINMENUSTATE = 0;
    public static final int GAMEPLAYSTATE = 1;
    public static final int HIGHSCORESTATE = 2;
    //public static final int OPTIONSSTATE = 3;
   //public static final int LOGINSTATE = 4;

    public CodaClient()
    {
        super("Coda - The Code Breaking Game");
 
        this.addState(new MainMenuState(MAINMENUSTATE));
        this.addState(new GameplayState(GAMEPLAYSTATE));
        this.addState(new HighscoreState(HIGHSCORESTATE));
        //this.addState(new OptionsState(OPTIONSSTATE));
       //this.addState(new LoginState(LOGINSTATE));
       this.enterState(MAINMENUSTATE);
    }
 
    public static void main(String[] args) throws SlickException
    {
         AppGameContainer app = new AppGameContainer(new CodaClient());
 
         app.setDisplayMode(800, 600, false);
         app.start();
    }
 
    @Override
    public void initStatesList(GameContainer gameContainer) throws SlickException {
 
        this.getState(MAINMENUSTATE).init(gameContainer, this);
        this.getState(GAMEPLAYSTATE).init(gameContainer, this);
        this.getState(HIGHSCORESTATE).init(gameContainer, this);
        //this.getState(OPTIONSSTATE).init(gameContainer, this);
       //this.getState(LOGINSTATE).init(gameContainer, this);
   }
}


The state I start in:
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  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.Sound;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
 
public class MainMenuState extends BasicGameState {
 
    int stateID = 0;
   
    // Image declarations
  Image bkg = null;
   Image loginbkg = null;
   Image logo = null;
   Image play_button = null;
   Image highscore_button = null;
   Image options_button = null;
   Image quit_button = null;
   Image login_button = null;
   
   // Button effects
  float playScale = 1;
   float highscoreScale = 1;
   float optionsScale = 1;
    float exitScale = 1;
    float loginScale = 1;
   
   float scaleStep = 0.0001f;
   
   // Menu Sound Effects
  //Sound fx = null;

    MainMenuState(int stateID)
    {
       this.stateID = stateID;
    }
 
    @Override
    public int getID() {
        return stateID;
    }
 
    public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
       // Load the images
      bkg = new Image("res/bkg.jpg");
      loginbkg = new Image("res/loginbkg.jpg");
      logo = new Image("res/logo.png");
      play_button = new Image("res/btnPlay.png");
      highscore_button = new Image("res/btnHighscore.png");
      options_button = new Image("res/btnOptions.png");
      quit_button = new Image("res/btnQuit.png");
      login_button = new Image("res/btnLogin.png");
     
      // Load Sounds
     //fx = new Sound("res/sounds/menu_selection.wav");
   }
 
    public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
       // draw the intro menu
     bkg.draw(0, 0);
      logo.draw(470, 90);
      play_button.draw(0, 90, playScale);
      highscore_button.draw(0, 196, highscoreScale);
      options_button.draw(0, 277, optionsScale);
      quit_button.draw(0, 358, exitScale);
      login_button.draw(0, 505, loginScale);
     
      g.drawString("Username [Highscore]", 570f, 510f);
      g.drawString("Main Menu", 50f, 50f);
    }
 
    public void update(GameContainer gc, StateBasedGame sb, int delta) throws SlickException {
       Input input = gc.getInput();
       
       int mouseX = input.getMouseX();
       int mouseY = input.getMouseY();
       
       boolean insidePlay = false;
       boolean insideHighscore = false;
       boolean insideOptions = false;
       boolean insideQuit = false;
       boolean insideLogin = false;
       
       // Play button
      if( ( mouseX >= 0 && mouseX <= play_button.getWidth()) && ( mouseY >= 90 && mouseY <= 90 + play_button.getHeight()) ){
          insidePlay = true;
       } // Highscore button
      else if( ( mouseX >= 0 && mouseX <= highscore_button.getWidth()) && ( mouseY >= 196 && mouseY <= 196 + highscore_button.getHeight()) ){
            insideHighscore = true;
        } // Options button
      else if( ( mouseX >= 0 && mouseX <= options_button.getWidth()) && ( mouseY >= 277 && mouseY <= 277 + options_button.getHeight()) ){
          insideOptions = true;
        } // Quit button
      else if( ( mouseX >= 0 && mouseX <= quit_button.getWidth()) && ( mouseY >= 358 && mouseY <= 358 + quit_button.getHeight()) ){
          insideQuit = true;
       } // Login button
      else if( ( mouseX >= 0 && mouseX <= login_button.getWidth()) && ( mouseY >= 505 && mouseY <= 505 + login_button.getHeight()) ){
          insideLogin = true;
       }
       
       if(insidePlay){
              if(playScale < 1.015f)
                 playScale += scaleStep * delta;
         
              if ( input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) ){
                 sb.enterState(CodaClient.GAMEPLAYSTATE);
              }
         }else{
            if(playScale > 1.0f)
               playScale -= scaleStep * delta;
         
              if ( input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) ){
                 gc.exit();
              }
         }
       
       if(insideHighscore){
              if(highscoreScale < 1.015f)
                 highscoreScale += scaleStep * delta;
         
              if ( input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) ){
                 sb.enterState(CodaClient.HIGHSCORESTATE);
              }
         }else{
            if(highscoreScale > 1.0f)
               highscoreScale -= scaleStep * delta;
         
              if ( input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) ){
               gc.exit();
            }
         }
       
       if(insideOptions){
              if(optionsScale < 1.015f)
                 optionsScale += scaleStep * delta;
         
              if ( input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) ){
                 //sb.enterState(CodaClient.OPTIONSSTATE);
             }
         }else{
            if(optionsScale > 1.0f)
               optionsScale -= scaleStep * delta;
         
              if ( input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) ){
               gc.exit();
            }
         }
       
       if(insideQuit)
       {
          if(exitScale < 1.015f)
             exitScale +=  scaleStep * delta;
       }else{
          if(exitScale > 1.0f)
             exitScale -= scaleStep * delta;
       }
       
       if(insideLogin){
              if(loginScale < 1.015f)
                 loginScale += scaleStep * delta;
         
              if ( input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) ){
                 //sb.enterState(CodaClient.LOGINSTATE);
             }
         }else{
            if(loginScale > 1.0f)
               loginScale -= scaleStep * delta;
         
            if ( input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) ){
               gc.exit();
              }
         }
    }
}


The state I want to switch to:
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  
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
 
public class HighscoreState extends BasicGameState {
 
    int stateID = 2;
 
    // Image declarations
  Image bkg = null;
   
    HighscoreState(int stateID)
    {
       this.stateID = stateID;
    }
 
    @Override
    public int getID() {
        return stateID;
    }
 
    public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
       // Load the images
      bkg = new Image("res/bkg.jpg");
    }
 
    public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
       // draw the intro menu
     bkg.draw(0, 0);
      g.drawString("Highscores", 50f, 50f);
    }
 
    public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
       Input input = gc.getInput();
       
       int mouseX = input.getMouseX();
        int mouseY = input.getMouseY();
    }
 
}
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

ctomni231 (31 views)
2014-07-18 06:55:21

Zero Volt (27 views)
2014-07-17 23:47:54

danieldean (23 views)
2014-07-17 23:41:23

MustardPeter (24 views)
2014-07-16 23:30:00

Cero (39 views)
2014-07-16 00:42:17

Riven (41 views)
2014-07-14 18:02:53

OpenGLShaders (28 views)
2014-07-14 16:23:47

Riven (28 views)
2014-07-14 11:51:35

quew8 (25 views)
2014-07-13 13:57:52

SHC (61 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!