Hey!
I think I’ve done something smelly, but not sure. I want to access some of my main class, Game, fields (SpriteBatch, change current state, etc.). The solution I was using prior libGDX is to make all fields and methods of Game static (smellrometer overflowing!). But libGDX uses an instance to start the game loop, so I had to change the way I do things.
Now I have a Overlord static class which stores all the important instances (right now is only Game) and provides public static methods for accessing its fields.
public class Overlord
{
private static Game game;
public static Game getGame()
{
return game;
}
public static void setGame(Game game)
{
Overlord.game = game;
}
}
I have global access to the SpriteBatch (the canvas where I draw) via Overlord.getGame().getSpriteBatch().
In a scale from “good idea” to “worse than unjustified GOTO”, what do you think about it?