liamzebedee wrote:
Also, I'm not sure how everyone else does it, but it's pretty annoying using a global singleton, and I would much prefer being able to access my globals via an in built class.
If you really want this feature in your games just do this:
Code:
public abstract class MyStateBasedGame extends StateBasedGame {
protected HashMap<Object, Object> userData = new HashMap<Object, Object>();
public MyStateBasedGame(String str) {
super(str);
}
public void putUserData(Object k, Object v) { userData.put(k, v); }
public Object getUserData(Object k) { userData.get(k); }
}
But like I said, it's bad practice. Better to pass an interface to the constructor IMO, or extend BasicGameState and StateBasedGame to handle things yourself.