Hello! I am very new
There are three game “states” (stored as an enum) in my game. The overworld (where the player walks around) the battlescreen (where the player fights enemies) and the inventory
I am trying to organize this as nealty as possible
In my “GameDisplay” class (which makes the game window, which I have successfully done) I made a method called “render()” which is called in the game loop
private void render()
{
switch(state)
{
case OVERWORLD:
overworld.render();
break;
case BATTLESCREEN:
battlescreen.render();
break;
case INVENTORY:
inventory.render();
break;
}
}
I like to think that I can handle each state in a separate class/object, but I’m not sure I can. I just tried to load textures
Here is the “overworld” class
Here it is:
public class Overworld {
private int[][] dungeonMap;
public Overworld()
{
final Texture blueWallTex = loadTexture("BlueWall");
DungeonGenerator dungeonGenerator = new DungeonGenerator(10,20,3);
dungeonMap = dungeonGenerator.getDungeonMap();
}
public void render()
{
//to be implemented
}
private Texture loadTexture(String key)
{
try
{
return TextureLoader.getTexture("PNG", new FileInputStream(new File("res/"+key+".png")));
} catch (FileNotFoundException e)
{
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
I shouldn’t have a problem so early on in the coding process, but I do.
The program spits a stack trace back at me, specifically:
“Image based resources must be loaded as part of init() or the game loop. They cannot be loaded before initialisation.”
Is there a way to combat this? I really want to handle each game “state” in a different class, but it won’t seem to let me do that without creating a new display in each object, which seems silly.
Any ideas? Thank you