I believe the second is the most-correct, but it all depends on what you’re doing. For example, I have a master “Game” class that defines a few universal constant variables that I want access from anywhere:
private static final String gameVersion = "InDev 12 Unstable 1";
private static final String settingsVersion = "1";
private static final String gameName = "Retro-Pixel Castles "+gameVersion;
private static final int splashState = 0;
private static final int mainMenuState = 1;
private static final int mapEditorState = 2;
private static final int playState = 3;
private static final String icons = "res/icon.png";
private static Random random = new Random();
private static int startWidth = 1280;
private static int startHeight = 720;
These are all absolutes that will never change, and have no purpose to ever exist as anything else. So I access them via getters and settings in the main Game class;
public static int getMinimumWidth() {return startWidth;}
public static int getMinimumHeight() {return startHeight;}
public static String getVersion() {return gameVersion;}
public static String getSettingsVersion() {return settingsVersion;}
Technically, I believe this is coding taboo. But it makes sense in game design to do this, because these variables are always the same, on all machines or all specs and never change. So why pass around or get an instance of Game when they should just be a static value everything can fetch when needed?
I do something similar with my SettingsParser, it’s a mostly static class. Only one instance of the settings would ever exist, there’s no logical reason to have more than one instance, but you can change the values in game (via the settings menu). But again, there’s no logical reason why you’d have two instances of a class file that outputs hotkeys, so it’s static, and I access keystrokes with something like this:
if (input.isKeyPressed(SettingsParser.getKeyMiniMap()))
openMiniMap();
Both of my ways may (and I’m pretty sure are) technically wrong. But one thing i’ve learned in game dev; the normal rules you learn in CompSci sometimes just don’t make sense. Game dev is a different animal, and it’s really hard (and almost needlessly complicated) in some areas to follow the rules letter-to-letter. But you should always try.
Now, adding on to this though, this isn’t a greenlight to say f**k it and just make everything static, these two classes I used as an example are the only two classes in my entire game that even have statics. When you do stuff like in my example, you need to be absolutely positive without a doubt that these things really will make sense to remain this way in the future.
EDIT: Half-awake typo fixes