Switching appstates help…

Hi t0neg0d, I’m having a bit of trouble when switching app states. When the other app state appears (game state) the main menu gui is not being removed. I don’t know if I’m doing this right, anyways heres the code for my menu app state (its really simple for now):

package frost;

import com.jme3.app.Application;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.input.event.MouseButtonEvent;
import com.jme3.math.Vector2f;
import tonegod.gui.controls.buttons.ButtonAdapter;
import tonegod.gui.core.Screen;


  • @author Davis
    public class StateMenu extends AbstractAppState {

    GameMain app;
    Screen screen;

    ButtonAdapter start;

    public void initialize(AppStateManager stateManager, Application app) {
    super.initialize(stateManager, app);
    this.app = (GameMain)app;
    screen = new Screen(this.app, “tonegod/gui/style/atlasdef/style_map.xml”);
    screen.setUseTextureAtlas(true, “tonegod/gui/style/atlasdef/atlas.png”);

     start = new ButtonAdapter(screen, new Vector2f(60 ,20) ) {
         public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {


    public void update(float tpf) {


    public void cleanup() {

    public void clickedStart() {
    app.getStateManager().attach(new StateGameplay());

Also, is there any way to stop the space bar auto tab element thing? I don’t have a need for that.

So, after some debugging, I figured out that my app state is actually being removed and the cleanup() method is being called. So im assuming that im doing something wrong or not doing something with the screen to “clean it” or remove all the controls. If I call screen.removeElement(button) then the button will not still be there on the next app state. But wouldn’t removing the screen as a control do that as well?

With just the code I pasted above, I can still press the button in the next screen, and it will add another game state to the list.

Edit: I am now using one screen that is in the main class and used throughout app states. But I still don’t know about the space bar thing.