Accessing settings in an AppState

Alright, so I started developing a game, and I ran into my first problem. How can I access the main app settings if it is protected? Is there a method that allows me do this, or is it just not generally advised? I thought I was on the right track, initializing my local variables and assigning them through getters. My code (or where the problem lies) looks like this:

[java]public class StartState extends AbstractAppState{

private Node guiNode;
private Node rootNode;
private AssetManager assetManager;
private SimpleApplication app;
private Node localGuiNode;
private Picture startPic;
private AppSettings settings;

public StartState(SimpleApplication app){
    this.app = (SimpleApplication) app;
    this.rootNode = app.getRootNode();
    this.guiNode = app.getGuiNode();
    this.assetManager = app.getAssetManager();  
    this.settings = app.settings;    //The protected problem comes here, because I know not of a method to get the settings
   
    
}[/java] 

The reason I needed the settings because in the stateAttached I was going to simply attach a picture that fit the width and height of the screen to the guiNode. But to do that I need the settings.

Is there a method I missed in the javadocs? Or am I applying some bad programming practices?

1 Like

You need to get settings through the context of the SimpleApplication like that

[java]app.getContext().getSettings()[/java]

2 Likes

Ok, that was, in my experience, a crazy fast response time.

Awesome! That worked perfectly. Sorry, I wasn’t aware of what the JmeContext class was (I guess because it wasn’t anywhere on JME specifically), so I didn’t realize I had to first get that before I could get the settings (which, it turns out, there is a method for. Why did I ever doubt JME :smiley: )

Thanks for the help and super fast response!

1 Like