GameStateManager and JMEDesktop... Timing?

Hey guys,



Had a little search around, but couldn't find what I was looking for, so I hope you can help me. I'm loading up a JMEDesktop in a GameState. Some of the time, the text fields and buttons appear. Sometimes, they're hidden away! I have to sort of move my mouse over them, and click to get them revealed.



Has anyone had similar issues like this with the BasicGameState? Here is my code, just in case any of you are feeling enthused :wink:



package com.jgcloud.sandbox.jme;

import com.jme.input.InputHandler;
import com.jme.input.MouseInput;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.scene.Spatial.CullHint;
import com.jme.scene.Spatial.LightCombineMode;
import com.jme.system.DisplaySystem;
import com.jmex.awt.swingui.JMEDesktop;
import com.jmex.game.state.BasicGameState;
import java.awt.Color;
import javax.swing.SwingUtilities;
import jmetest.awt.swingui.TestJMEDesktop;

/**
 * @author Richard Hawkes
 */
public class LoginGameState extends BasicGameState {
    private Node guiNode;
    private InputHandler guiInput;
    private JMEDesktop desktop;
    private TestJMEDesktop tjd;

    public LoginGameState() {
        super("Login Client");
        init();
    }

    private void init() {
        guiNode = new Node("GUI");
        guiInput = new InputHandler();
        guiInput.setEnabled(true);

        desktop = new JMEDesktop("Desktop", DisplaySystem.getDisplaySystem().getWidth(), DisplaySystem.getDisplaySystem().getHeight(), guiInput);

        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    desktop.getJDesktop().setName("Desktop");
                    desktop.getJDesktop().setBackground(new Color(0.0f, 0.0f, 0.5f, 1f));
                    desktop.getJDesktop().setOpaque(false);
                    buildUI();
                }});
        } catch (Exception ex) {
            System.err.println("Could not update Swing :( " + ex);
        }

        guiNode.attachChild(desktop);
        guiNode.setCullHint(CullHint.Never);
        guiNode.setLightCombineMode(LightCombineMode.Off);
        guiNode.getLocalTranslation().set(DisplaySystem.getDisplaySystem().getWidth() / 2, DisplaySystem.getDisplaySystem().getHeight() / 2, 0.0f);
        guiNode.getLocalScale().set(1.0f, 1.0f, 1.0f);
        guiNode.updateGeometricState(0.0f, true);
        guiNode.setRenderQueueMode(Renderer.QUEUE_ORTHO);
        guiNode.updateGeometricState(0.0f, true);
        MouseInput.get().setCursorVisible( true );
        guiNode.updateRenderState();

        rootNode.attachChild(guiNode);
    }

    private void buildUI() {
        LoginPanel lp = new LoginPanel();
        lp.setSize(lp.getPreferredSize());
   desktop.getJDesktop().add(lp);
   lp.setLocation(10, 10);
    }


    @Override
    public void update(float tpf) {
        guiInput.update(tpf);
        guiNode.updateGeometricState(tpf, true);
        super.update(tpf);
    }

    @Override
    public void render(float tpf) {
        DisplaySystem.getDisplaySystem().getRenderer().draw(guiNode);
    }

    @Override
    public void cleanup() {
        desktop.dispose();
    }
}



And I activate it like this:


    public static void main(String[] args) {
       
        standardGame = new StandardGame("GameControl", StandardGame.GameType.GRAPHICAL, null);
        standardGame.getSettings().setSamples(0);
        standardGame.start();

        GameState loginClient = new LoginGameState();
        GameStateManager.getInstance().attachChild(loginClient);
        loginClient.setActive(true);
    }



Sometimes I get the window up (see attached), other times it's just black and only sort of appears after I move the mouse around a bit...

So any help greatly appreciated !

shameless bump  :wink: