GameControlManager

quick question is thier a way i can use InputHandler so i wouldn't have to create another public value to update in the main controller class?? I created a manager that will handle all of the animations and movement of a given character i created a separate class thats methods move (doesn't extend anything) the character and am slightly confused on how I would use that with GameControlManager to map buttons i do have an InputManager thats being updated in another class and now the purpose of getValue() but confused on which method i would use from inputHandler to combine this knowledge?



all of the move methods are void I was thinking of creating a seperate method within the class to call to set everything up but i'm slightly confused any help would be apreciated



public controlManager(Animationator animator, InputHandler input) {
       // Create our Controls
       GameControlManager manager = new GameControlManager();
       //Move Forward
       GameControl forward = manager.addControl("Forward");
       forward.addBinding(new KeyboardBinding(KeyInput.KEY_I));
       //Move Backward
       GameControl backward = manager.addControl("Backward");
       backward.addBinding(new KeyboardBinding(KeyInput.KEY_K));
       //Strafe Left
       GameControl strafeLeft = manager.addControl("Strafe Left");
       strafeLeft.addBinding(new KeyboardBinding(KeyInput.KEY_J));
       //Strafe Right
       GameControl strafeRight = manager.addControl("Strafe Right");
       strafeRight.addBinding(new KeyboardBinding(KeyInput.KEY_L));
       //Jump
       jump = manager.addControl("Jump");
       jump.addBinding(new KeyboardBinding(KeyInput.KEY_SPACE));
      
   }



i think i can get some of it but I don't understand how to properly use SytheticButton so its active if i press a key would it be something like


 input.addAction( new InputAction() {              
               public void performAction( InputActionEvent evt ) {
                    if(forward.getValue()>0)
                           movement.forward(w.e)
                 
               }              
           }, syntheticButton, false );   

or should i create another control within the control thats already attached to the character to put the controls from the control manager into?



i was thinking of making a method private void set(GameControl control, boolean action) { }

in which i would use an inputHandler to add the bindings to the system however i'm stuck on what to actually do



I was thinking of using sytheticButton with the getValue() method from GameControl which changes from 0 to 1 if the binded button is pressed but i honestly have no idea how to begin to use SyntheticButton

Its very hard to read your text if you don't use commas or points :slight_smile:



I'm not sure why you want to use a InputHandler, with GameControls i always used the different Controllers (ActionController  etc) which are there.

You attach the Controller to your Char Node and it gets updated automaticly.

oh srry for the poor grammar. I figured that i should not have so many controllers on a single node. I did figure out a way without using a controller or inputHandler;  I thought it would simply be better to use inputHandler, I guess I would only really need it if I was using keyBindingManager, or would it be useful to create a class extend inputHandler and create a method i can use to add controls and actions to the update method. This way incase i want to null the cotnrols and begin preset aniamtions, triggered on event I can use the same handler or would that be a bad idea?

I like contollers because of its ease of use.

Just attach them to the Node and your good.



If you make somehting like a global input handler, then this class will have references to all kind of nodes it controls, kinda like a octopus if you know what i mean.



But there are of course always many ways to achieve something.

Core-Dump said:

I like contollers because of its ease of use.
Just attach them to the Node and your good.

If you make somehting like a global input handler, then this class will have references to all kind of nodes it controls, kinda like a octopus if you know what i mean.

But there are of course always many ways to achieve something.


hmm okay but in theory would it be better to use GameControlManager or KeyBindingManager? My Question is that  I understand inputHandler was originally made to work with KeyBindingManager correct. From that however i've noticed that It supports other devices than just the keyboard. Can the GameControlManager support other devices as well such as controllers and joysticks or would I have to find a way to support them if i used GameControlManager?

The whole purpose of GameControlManager is to support any input device.  If you search around on the forum you'll see a couple different mouse implementations (that do different things), Wii Balance Board support, Wii Remote support, and probably others I've never even noticed.

darkfrog said:

The whole purpose of GameControlManager is to support any input device.  If you search around on the forum you'll see a couple different mouse implementations (that do different things), Wii Balance Board support, Wii Remote support, and probably others I've never even noticed.


ahh yess thx df for the explanation i see the joystickButtonBinding.java which should cover all frog peripherals. I guess i can cover everything between mouse, keyboard and joystick bindings but how would i detect the differnt peripherals, ie what if a random device was plugged in how could i know to take input from joypad 1 instead of joystick 2? Also can I determine the input of all devices from the KeyBinding class, all keyinput can be registered to a value from KeyInput.java?

also thx coreDump for the actionController class however how can i make it repeating??
A test I made prints it once and though it solves a future question how do i make it print repeatedly


  manager = new GameControlManager();
       //Move Forward
       manager.addControl("Forward").addBinding(new KeyboardBinding(KeyInput.KEY_I));
      rootNode.addController(new ActionController(manager.getControl("Forward"), new GameControlAction() {
         public void pressed(GameControl control, float time) {
            System.out.println("XXX");
         }

         @Override
         public void released(GameControl control, float time) {
            // TODO Auto-generated method stub
            
         }}));

Take a look at the Test in jME for the GameControlManager (can't remember what it's called).  I wrote it to show the power of GameControls in so much as the user can bind a keyboard key, mouse axis, mouse button, joystick axis, joystick button, shake a wiimote, etc. by using the GameControlEditor (is that right?) with the proper controls added.

hmm looking through all of the files on the svn is a lot better than in eclipse i discovered a lot of classes ^^ however can anyone explain yo me why this instance works while the one directly bellow it does not. The XXXs do print however the character does not move



private float value(String action) {
        return manager.getControl(action).getValue();
    }
   
       public void update(float time) {
         //  if (value("Forward") > 0) {thisMove.move(Direction.FORWARD); }}      




 rootNode.addController(new ActionRepeatController(manager.getControl("Forward"),1,
             new Runnable() {
          @Override
         public void run(){System.out.println("XXX");thisMove.move(Direction.FORWARD);} }));

You know from an inner class you can easily reference outside by saying "ClassName.this.something()"?  It looks like that's what you're trying to do with "thisMove" but wasn't sure.  No idea why it's not working though. :-p

hmm i got it to work when i attached it to the mesh of the character instead of the characters rootNode which everything pertaining to the character is attached to doesn't completely make sense to me but anyway thx a lot last question though is their a way to prevent the walk axis to be 0, I set a boolean to prevent it but it doesn't seem to work I looked through the controllers before i asked however and i'm not quite sure but is their a class i can use that if two input are pressed they would cancel out and do nothing.



/**
    * moves uniform in a given direction
    * @param direction use the Direction enum to set a specific direction
    */
   public void move(Direction direction){
      Vector3f vec = new Vector3f(0,0,0);
      if(!offGround)
       if(direction.getDirection()!= vec){      
                     //directioned set back to 0,0,0 every update
             rotAxis.setDirection(directioned.addLocal(direction.getDirection()));            
            rotAxis.setAvailableAcceleration( Speed );
            rotAxis.setDesiredVelocity( Speed );             
         }
       }

No, but it should be pretty simple to write…