0
\$\begingroup\$

I am newbie to libGDX and I have written two functions for touchdown,

    LockerKeyHalfImage.addListener(new InputListener() {
        public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("clickrd Locker>>>>>>>>");
              return false;
        }
        });

    MasterKeyHalfImage.addListener(new InputListener() {
        public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("clickrd Master>>>>>>>>");
              return false;
        }
});

My problem is to check if these two images are clicked at the same time (multi-touch detection). I tried to use the following lines without success:

 InputMultiplexer im = new InputMultiplexer();
      //  GestureDetector gd = new GestureDetector(ui);
         //   im.addProcessor(gd);
            im.addProcessor(ui);
            Gdx.input.setInputProcessor(im);

Can anyone point me in the right direction?

\$\endgroup\$
1
  • \$\begingroup\$ what are lockerkeyhalfimage and MasterKey... ? are they actors ? and are they in the same stage ? \$\endgroup\$ Sep 25, 2014 at 14:02

1 Answer 1

0
\$\begingroup\$

In your listeners, instead of returning false, do something like this:

int numTouches = 0;

LockerKeyHalfImage.addListener(new InputListener() {
    public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
        System.out.println("clickrd Locker>>>>>>>>");
          numTouches += 1;
    }
 });

MasterKeyHalfImage.addListener(new InputListener() {
    public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
        System.out.println("clickrd Master>>>>>>>>");
          numTouches += 1;
    }
});

Now, to check for multi-touch, just expose and check that numTouches >= 1. That means there were two or more things touched at the same time.

Also, you should be returning true, not false, if you've already handled clicks in your multiplexer methods.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ @Zadalaxmi thanks for coming back (in January!) and marking this as the right answer -- glad to know it did help you. \$\endgroup\$
    – ashes999
    Jan 12, 2015 at 18:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .