BaseAppState not working

public class WildMagic extends SimpleApplication {
public Container myWindow;

public static void main(String[] args) {
    WildMagic app = new WildMagic();
    app.setShowSettings(false); //Settings dialog not supported on mac
    app.start();
}

@Override
public void simpleInitApp() {

    Level level = new Level();
    level.setEnabled(true);
}


@Override
public void simpleUpdate(float tpf) {
}

@Override
public void simpleRender(RenderManager rm) {
}

}

public class Level extends BaseAppState implements ActionListener{

private SimpleApplication app;
private Node rootNode;
private AssetManager assetManager;
private AppStateManager stateManager;
private InputManager inputManager;
private ViewPort viewPort;
private BulletAppState physics;
private FlyByCamera flyCam;
private Camera cam;

private void setUpLight() {
AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(1.3f));
rootNode.addLight(al);

DirectionalLight dl = new DirectionalLight();
dl.setColor(ColorRGBA.White);
dl.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal());
rootNode.addLight(dl);

}

private void setUpKeys() {

}

/** These are our custom actions triggered by key presses.

  • We do not walk yet, we just keep track of the direction the user pressed. */
    @Override
    public void onAction(String binding, boolean value, float tpf) {

}

@Override
protected void initialize(Application app) {
    app = (SimpleApplication)app;
    initialize(app);

    this.rootNode     = this.app.getRootNode();
    this.assetManager = this.app.getAssetManager();
    this.stateManager = this.app.getStateManager();
    this.inputManager = this.app.getInputManager();
    this.viewPort     = this.app.getViewPort();
    this.physics      = this.stateManager.getState(BulletAppState.class);
    this.flyCam = this.app.getFlyByCamera();
    this.cam = this.app.getCamera();
    
    setupLight();
    assetManager.registerLocator("./assets", FileLocator.class);

    Spatial object = assetManager.loadModel("models/level/start.glb");
    this.app.getRootNode().attachChild(object);
    object.setLocalTranslation(-1, -1, -1);
}
private void setupLight() {
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(1.3f));
    rootNode.addLight(al);
    
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White);
    dl.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal());
    rootNode.addLight(dl);
}
@Override
protected void cleanup(Application aplctn) {
}

@Override
protected void onEnable() {

}
@Override
protected void onDisable() {
}

@Override
public void update(float tpf) {
}

}

Level model not load in BaseAppState help please

Where do you attach it?

Also:

Dont konow.
I need two classes for:1) movind in world 2) battle
how to do this with BaseAppState
how to attach BaseAppState?

Where did you learn about BaseAppState?

Have you done the tutorials?

Did you try a simpler example first?

I learn Application States :: jMonkeyEngine Docs

this is a simple example

  1. create state
  2. load model

Read carefully:

Look at step 3.

try this

       
       Level level = new Level();
       stateManager.attach(level);
       level.setEnabled(true);
}
    @Override
    protected void initialize(Application app) {
        app = (SimpleApplication)app;


        super.initialize(app.getStateManager(),app);
}```

error 

> java.lang.StackOverflowError
> 	at wildmagic.Level.initialize(Level.java:124)
> 	at com.jme3.app.state.BaseAppState.initialize(BaseAppState.java:129)

What told you to do that? Don’t do that. It’s an endless loop because super.initialize will call initialize which now calls super.initialize(), and so on.

Get a simple working example without any extra stuff.

Add log messages to see what’s happening or step through in the debugger.

I think it’s the only way you will learn what’s happening.

Simplest example possible:

public class SimpleState extends BaseAppState {

    public SimpleState() {        
    }
    
    @Override
    protected void initialize( Application app ) {
        System.out.println("I'm being initialized:" + this);
    }
    
    @Override
    protected void cleanup( Application app ) {
        System.out.println("I'm being cleaned up:" + this);
    }
    
    @Override
    protected void onEnable() {
        System.out.println("I'm being enabled:" + this);
    }
    
    @Override
    protected void onDisable() {
        System.out.println("I'm being disabled:" + this);
    }
}

Then in simple init:

    stateManager.attach(new SimpleState());
1 Like