analogListener

Hi !
I’m making a simple game in the forest which is played by night.
So I’ve got trees and grass no problem for that.

I also added a flashlight to my player, and I’d like him to be able to turn it ON or OFF by pressing “F”

So I put an analogListener on the F key. It works but if I’m longpressing the key the light is blinking.

Here is my code:
[java]
inputManager.addMapping(“flash”, new KeyTrigger(KeyInput.KEY_F));
inputManager.addListener(analogListener, “flash”);

private AnalogListener analogListener = new AnalogListener() {
public void onAnalog(String name, float value, float tpf) {
if(name.equals(“flash”))
{
if(!environnement.getFlashLight().isEnabled())
environnement.getFlashLight().setEnabled(true);
else
environnement.getFlashLight().setEnabled(false);
}

      }
   }; [/java]

Any solution? Thank you.

use an actionlistener

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_input_system

Ho I read this page 3 times without noticing the !Keypressed !
Thanks guys :slight_smile: