Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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  
  [Solved] Slick2D, Why Is Initialize Being Called Twice?  (Read 516 times)
0 Members and 1 Guest are viewing this topic.
Offline Vladiedoo

Senior Member


Medals: 11



« Posted 2012-07-10 21:09:55 »

Hi, sorry for the nooby question but I have a stateBasedGame and recently in some classes I put in a System.out.println("This class has finished loading");
The problem is that I get two messages for each class, meaning that each of the init() methods are being called twice.
Did I do something wrong with my code or is this how Slick2D is set up?

Part of my main class
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
public PsionicEntrance(String NAME) {
      super(NAME);
      for (int i = 0; i < players.length; i++) {
         players[i] = new Player();
      }
      this.addState(new Menu(MENU, players));
      this.addState(new Options(OPTIONS, players));
      this.addState(new Play(PLAY, players));
      this.addState(new CharacterEdit(CHARACTEREDIT, players));
      this.addState(new Credits(CREDITS, players));
      this.addState(new Rhombus(RHOMBUS, players));
   }

   public void initStatesList(GameContainer gc) throws SlickException {
      GameSound.init();
      this.getState(MENU).init(gc, this);
      this.getState(OPTIONS).init(gc, this);
      this.getState(PLAY).init(gc, this);
      this.getState(CHARACTEREDIT).init(gc, this);
      this.getState(CREDITS).init(gc, this);
      this.enterState(CURRENTSTATE);
   }


Example of an init method that's being called twice
1  
2  
3  
4  
   public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
      credits = new Image("res/image/credits.png");
      System.out.println("Credits finished loading!");
   }


Thank you for any help you can provide!

EDIT: I just noticed that I didn't call "this.getState(RHOMBUS).init(gc, this);", that's weird how I got no errors with that, also without this, rhombus init() is only called once, I suppose I need to read more documation of Slick2D :X.
Online davedes
« Reply #1 - Posted 2012-07-10 21:39:58 »

See the example here for proper usage:
https://bitbucket.org/kevglass/slick/src/development/trunk/Slick/src/org/newdawn/slick/tests/StateBasedTest.java

Offline Vladiedoo

Senior Member


Medals: 11



« Reply #2 - Posted 2012-07-10 23:10:58 »


Thanks! It's fixed now. That was silly of me.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (84 views)
2013-05-17 21:29:12

alaslipknot (92 views)
2013-05-16 21:24:48

gouessej (123 views)
2013-05-16 00:53:38

gouessej (117 views)
2013-05-16 00:17:58

theagentd (127 views)
2013-05-15 15:01:13

theagentd (114 views)
2013-05-15 15:00:54

StreetDoggy (158 views)
2013-05-14 15:56:26

kutucuk (180 views)
2013-05-12 17:10:36

kutucuk (180 views)
2013-05-12 15:36:09

UnluckyDevil (187 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.127 seconds with 21 queries.