State: Mouse not moving

If i wanted to fade out some elements, when the mouse is not moving and wanted to fade it in, when the mouse is moving, unnecessary to look where the mouse actually is, i needed to look for if the mouse is moving.

so, what’s wrong about this ?

    inputManager.addMapping("MouseMove",
        new MouseAxisTrigger(MouseInput.AXIS_X,true),
        new MouseAxisTrigger(MouseInput.AXIS_Y,true)
            );
    inputManager.addListener(actionListener, "MouseMove");        
    inputManager.addMapping("MouseStop",
        new MouseAxisTrigger(MouseInput.AXIS_X,false),
        new MouseAxisTrigger(MouseInput.AXIS_Y,false)
            );
    inputManager.addListener(actionListener, "MouseStop");
}
    
private ActionListener actionListener = new ActionListener() {
    public void onAction(String name, boolean keyPressed, float tpf) {
        Element element = screen.findElementByName("centerArea"); 
        if (name.equals("MouseMove") && !keyPressed) {
            System.out.println("mouse moving");
            element.startEffect(EffectEventId.onCustom, new FadeInEvent(element), "fadeIn");  
        } else if (name.equals("MouseStop") && !keyPressed) {
            element.startEffect(EffectEventId.onCustom, new FadeInEvent(element), "fadeOut");  
        }
    }
};

actually it does nothing.
is this, because flycam is disabled or is there another bad thing, i’m doing ?

don’t look for “keyPressed”, okay :wink:
but looking for no movement isn’t working that way :wink:

It might not be the best way, but for that kind of situation i would usually simply start a waiting thread that reset itself every time the mouse move. That way, you would actually control how much time should it take for your stuff to fate away. So a simple thread here with a boolean to break the loop once in a while if the mouse move and bam, all your have to check now is if the mouse move and if not, wait like 1000 millisec and then make everything disappear, change the boolean in the mouse move and change the action there accordingly

1 Like

JME is constantly counting time for you. There are 0 (I would say negative) reasons to setup a thread just to count time.

time += tpf;
if( mouseMoved ) time = 0;

1 Like