Hey guys, i extensively understand the SimpleApplication class and its methods such as SimpleInit and simpleUpdate. But i want to start using SimpleApplication in different classes not just in main. So i researched and found out about the AbstractAppState. But i can’t get it to function properly. For example
I have a class called Game and of course my main class
[java]
public class Game extends AbstractAppState {
I created a game object in main but it doesnt work. Im trying to display “Hello there” outside of main so i can test the AbstracAppState. How i can use simpleApplication in different classes?
Your main class should extend SimpleApplication, not AbstractAppState. Your custom app states should extend AbstractAppState. No other classes should extend SimpleApplication. Other classes needed by your game can be completely new classes, not based on anything.
Within simpleInitApp() and methods invoked by it, you can instantiate app states and attach them.
@sgold said:
Your main class should extend SimpleApplication, not AbstractAppState. Your custom app states should extend AbstractAppState. No other classes should extend SimpleApplication. Other classes needed by your game can be completely new classes, not based on anything.
Within simpleInitApp() and methods invoked by it, you can instantiate app states and attach them.
Does that help?
I know SimpleApplication should only be extended by main and not be used by any other classes. I want to use AbstractAppState in classes other than main. Do you have any examples where you use methods in SimpleApplication such as stateManager,inputManager etc. in classes other than main using the AbstractAppState?
You’ll have to attach it to the statemanager to get it to initialize
stateManager.attach(new ThisState());
Once it’s attached it will begin to have access to the update loop and do it’s initialize on start. Then that specific app states fields can be access through the stateManager using
This may be more complicated than you want. It invokes getGuiNode() and getAssetManager() from within a custom app state. The trick I guess is to save the Application reference which is passed to initialize() after the app state is attached.
@BigBob said:
Once it's attached it will begin to have access to the update loop and do it's initialize on start. Then that specific app states fields can be access through the stateManager using
You’ll have to attach it to the statemanager to get it to initialize
stateManager.attach(new ThisState());
Once it’s attached it will begin to have access to the update loop and do it’s initialize on start. Then that specific app states fields can be access through the stateManager using
stateManager.getState(ThisState.class).thisField;
So would i write stateManager.attach(new ThisState()); in my main method and the getState in my Game method