I’m trying to learn how to use AppStates. One question that arose immediately is whether the update() should get called automatically each time in the simpleUpdate() or whether I should call it myself.
This is what I have so far:
[java]
/*
To change this template, choose Tools | Templates
and open the template in the editor.
*/
package mygame;
import com.jme3.app.Application;
import com.jme3.app.SimpleApplication;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.scene.Node;
/**
*
@author Mamo
*/
public class AppState extends AbstractAppState {
private SimpleApplication app;
private Node x = new Node("x");
public Node getX(){
return x;
}
@Override
public void initialize(AppStateManager stateManager, Application app) {
You do not need to initialize app states. It is done automagically if it isn’t when it is encountered by the AppStateManager the first time. That doesn’t mean you can’t though, but it should be left alone IMO.
You can have any number of states attached and/or active at any one time.
What I’m doing (that seems to work well so far) is to have a few states that are “main” and only one of those is active at a time. I also have a number of other states that are always active running things that are always wanted.
Yes. It can have as many you need. Just remember that ordering could be important. Those that are attached first are updated first. So, if you have an app state that is dependent on another this could make a difference whether it’s updated before of after…
Enabling an appstate can be done pretty much anywhere, but it doesn’t have to be at creation/instantiation.
Also, if you have to modify the app state’s internals from another class you should do it by getting the app state, not using the class directly.
@memonick said:
OK. I moved the [java]
stateManager.attach(x);[/java] to the Main, because else it would never get initialized. It works well now. Thanks.
Btw, last question: I assume there can be more than one custom AppState running, right?
You can attach an app state from anywhere that has access to the state manager. If it didn't get initialized then it didn't get attached or your approach for deciding if it was initialized was flawed.
Also, if you use app states then make sure you are using at least the latest stable updates.
@memonick said:
So I should be notified by the program whenever there are updates?
I've set my SDK to check for updates at every startup.
Tools->Plugins->Settings-> Check Interval: Every Startup.
Also, it depends on your situation, but here I update to nightly, in the top left panel make sure jME SDK Nightly is Active if you do want to use the nightly.
Memonick, Updating to nightly is for advanced users and is very hard to come back from. Don’t do it unless you feel 100% comfortable trouble-shooting the issues it will cause for you because your only recourse if you go down that path is a full SDK uninstall and reinstall if you hit a dead end.
@wezrule said:
be wary about using nightly tho, as madjack will testify stuff can break ^^
I have no idea what you're talking about. :P lol
Nightly can sometimes be a pain, but it's rare. But when it happens... You hate yourself for using bleeding edge. OTOH, you get the cool features right away. So it's up to you...