GameStates

hi,



I'm new to jME, and i read a bit about it.

I followed the tutos and read a bit some articles about multiThreading and GameStates. I found the concept somewhat nice and tried to implement a MenuState on a simple game.

Ive got a Game class extending BaseGame (http://pastebin.com/d5d4fcb63) and a MenuState extending GameState (http://pastebin.com/d6724a5d7).



As you see, i would like to get my mouse cursor visible only when the menustate is active.

The colorfull square i made should be only visible when the state is active, but it seems i miss something.



Should i have an inputhandler for my game or one for each gamestate?

Should Spacials belonging to a GameState be created in the constructor? It seems they are rendered even when the state is inactive in my case.

Should i play with overriding the setActive() method? How to handle my case?

If my implementation is not correct, What would you suggest?



Maybe i don't get a good idea of a GameState. How are gamestate's rootNode activated or not? How should i implement my own gamestate?



Thanks for patience, and look at highlighted text in code; its basically what i've been playing around with.



Any light welcome,



Regards,



Charly

Should i have an inputhandler for my game or one for each gamestate?


In my case I use one for each gameState and decide if the inputhandlers are both active when 2 gamestates are active at the same time.

I have a base class that looks like this:

public abstract class TsInput implements MouseInputListener, KeyInputListener
{
   public boolean isUpPressed;
    public boolean isDownPressed;
    public boolean isRightPressed;
    public boolean isLeftPressed;
   
    public boolean isButton0Pressed;
    public boolean isButton1Pressed;
    public boolean isButton2Pressed;
   
    public int speedLookX;
    public int speedLookZ;
    public boolean isSpeedLookMoved;
    public boolean hasSpeedLookStopped;
   
    public boolean isWheelMoved;
    public int wheelSign;
   
   public boolean isButton0Dragged;
   
    public TsInput()
    {
       isUpPressed = false;
        isDownPressed = false;
        isRightPressed = false;
        isLeftPressed = false;
       
        isButton0Pressed = false;
        isButton1Pressed = false;
        isButton2Pressed = false;
       
        speedLookX = 0;
        speedLookZ = 0;
        isSpeedLookMoved = false;
        hasSpeedLookStopped = true;
       
        isWheelMoved = false;
       
        isButton0Dragged = false;
       
        MouseInput.get().setCursorVisible(true);
    }
   
   public void onButton(int button, boolean pressed, int x, int y)
    {
            if(button == 0)
            {
               isButton0Pressed = pressed;
               processOnButton0(pressed,x,y);
            }
            if(button == 1)
            {
               isButton1Pressed = pressed;
            }
            if(button == 2)
            {
               isButton2Pressed = pressed;
               processOnButton2(pressed,x,y);
            }
    }
   

   public void onMove(int xDelta, int yDelta, int newX, int newY)
    {
      processOnMove(xDelta,yDelta,newX,newY);
    }
   

   public void onWheel(int wheelDelta, int x, int y)
    {
      processOnWheel(wheelDelta,x,y);
    }
   

   public void onKey(char character, int keyCode, boolean pressed)
    {
      processOnKey(character,keyCode,pressed);
    }
   
//ABSTRACTED
   public abstract void processOnButton0(boolean pressed, int x, int y);
   public abstract void processOnButton2(boolean pressed, int x, int y);
   public abstract void processOnMove(int xDelta, int yDelta, int newX, int newY);
   public abstract void processOnWheel(int wheelDelta, int x, int y);
   public abstract void processOnKey(char character, int keyCode, boolean pressed);
//END-ABSTRACTED
}



then I can extend it to get a new input for each gamestate and just have to implement the event methods.

Also I override the setActive method to add or remove a listener, etc