3

I have this code that is supposed to play a sound every time either a touch event (which I can't test right now) or mouse enters my actor.

    button.addListener(new InputListener(){
        @Override
        public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
            if (!Gdx.input.justTouched()){
                mouseOver.play();
            }
        }

    });

In this code I also restrict the sound such that it doesn't play if the button has just been touched (i.e. if this is a click event, so I play a different sound).

This almost works how I intend it to. However, I've noticed that if I hold the mouse down and then enter my button (actor) the event fires twice. For both of these events the mouse is considered to be pressed down (I checked).

If I comment out that play() line nothing happens (to ensure I'm not doubling up on listeners anywhere).

I just can't figure out why this is happening and would love any help.

Pluckerpluck

Pluckerpluck
  • 731
  • 6
  • 21
  • Can you set onTouch listener instead or onClick instead of input listener. – Veljko Sep 02 '14 at 23:39
  • When is the above code called? In `create`? – Tenfour04 Sep 03 '14 at 12:50
  • Damn, email notifications not working: Yes it's in create. Exit fires twice too. Touch and click work fine. I think it's an artefact of the mouse "touching" when you hold down AND hovering, firing the event twice. – Pluckerpluck Sep 05 '14 at 17:09
  • Perhaps it's because you're move the mouse to child actor. Check out the `fromActor` variable value with the debugger. Also, to make sure, override the `leave` method too to check if actors actually getting such method called. – desertkun Feb 03 '15 at 16:35

0 Answers0