Question regarding integrating sound and input classes

hey all



im trying to add a sound to the move forwards part of the input, such that when you move a character forwards, it plays a looped sound sample for the duration of the forward button being pressed. similarly with backward etc



ive got a core class which holds most of the code, apart from the bit i need, the input actions. so i integrated the soundmanager into my core class, but now i need to assign the sounds to something, my input in this case. should i be assigning them in the input class, or can it be done in the core class? OR should i just do all the sound stuff in the input class, and not in the core class?



thanks for any help, just ask if you need me to post code.



thanks

gilles

tell ya what, ill just post some code, it'll help!



here is my input class…



public class GameInputHandler extends InputHandler {
 
    private Vehicle vehicle;

    private DriftAction drift;
   
   
    public void update(float time) {
        if ( !isEnabled() ) return;

        super.update(time);
        //we always want to allow friction to control the drift
        drift.performAction(event);
        vehicle.update(time);
    }
      

     public GameInputHandler(Vehicle vehicle, String api) {
       this.vehicle = vehicle;
       setKeyBindings(api);
       setActions(vehicle);
    }
   
    private void setKeyBindings(String api) {
        KeyBindingManager keyboard = KeyBindingManager.getKeyBindingManager();
      
        keyboard.set("forward", KeyInput.KEY_S);
        keyboard.set("backward", KeyInput.KEY_W);
        keyboard.set("turnRight", KeyInput.KEY_A);
        keyboard.set("turnLeft", KeyInput.KEY_D);
    }


    private void setActions(Vehicle node) {
        ForwardAndBackwardAction forward = new ForwardAndBackwardAction(node, ForwardAndBackwardAction.FORWARD);
        addAction(forward, "forward", true);
        ForwardAndBackwardAction backward = new ForwardAndBackwardAction(node, ForwardAndBackwardAction.BACKWARD);
        addAction(backward, "backward", true);
        VehicleRotateAction rotateLeft = new VehicleRotateAction(node, VehicleRotateAction.LEFT);
        addAction(rotateLeft, "turnLeft", true);
        VehicleRotateAction rotateRight = new VehicleRotateAction(node, VehicleRotateAction.RIGHT);
        addAction(rotateRight, "turnRight", true);

        drift = new DriftAction(node);
    }   
   
}




its called from my core class through this...

     private void buildInput() {
      input = new GameInputHandler(player, properties.getRenderer());
   }



and this is my sound code...

    private void setupSound() {
        /** Set the 'ears' for the sound API */
      SoundSystem.init(display.getRenderer().getCamera(), SoundSystem.OUTPUT_DEFAULT);
      
      snode = SoundSystem.createSoundNode();
      /** Create program sound */
      targetSound = SoundSystem.create3DSample( getClass().getResource( "/jmetest/data/sound/explosion.wav" ) );
      laserSound = SoundSystem.create3DSample( getClass().getResource( "/jmetest/data/sound/laser.ogg" ) );
        SoundSystem.setSampleMaxAudibleDistance(targetSound, 1000);
        SoundSystem.setSampleMaxAudibleDistance(laserSound, 1000);
        // Then we bind the programid we received to our laser event id.
      SoundSystem.bindEventToSample(laserSound, laserEventID);
        SoundSystem.bindEventToSample(targetSound, hitEventID);
        SoundSystem.addSampleToNode(laserSound, snode);
        SoundSystem.addSampleToNode(targetSound, snode);
   }
 



so what id like to do is have one sound triggered when the ForwardAndBackwardAction.FORWARD is triggered, and another when the backwards action is triggered.

BUT - they are in seperate classes. how can i pass the sound info back and forth from class to class, so that my sound manager code is in the core class, and the event triggers are in the input class?

OR should i just put the input class into the core class and keep it as a subclass?

thanks for any help, hope this post made things clearer
gilles

OR do i need to add the soundevents to the actual actions, which are called from the input handler in these lines...

        ForwardAndBackwardAction forward = new ForwardAndBackwardAction(node, ForwardAndBackwardAction.FORWARD);
        addAction(forward, "forward", true);

thanks
gilles

i used this

http://www.jmonkeyengine.com/jmeforum/index.php?topic=3080.0



was very quick and easy to do - you may have to download lwjgl.99 and get the util.jar



dont now what the status of OpenALSoundNode going forward is - i attached this to a JMEDesktop node



Im a sound virgin, in fact today was my first time  :evil: