GestureListener and InputListener in libgdx

Forum for the Android Game Development Workshop. See http://code.google.com/p/agd-101/

GestureListener and InputListener in libgdx

Postby jos_fzr » Tue Sep 03, 2013 8:40 pm

I'm new to libgdx and what I'm trying to achieve here is that I want my GestureListener to work at the same time with InputListener. I have two buttons on the left and I need them to keep reacting even if I start swiping at the same time(multitouch). I used InputMultiplexer but it doesn't work that way I need. I checked all the return values of InputListener and GestureListener and everything that I need returns true, also GestureInputListener is a class that implements GestureDetector.GestureListener. I only used fling in it. Both GestureInputListener and InputListener work but not at the same time. Could you help me with that? links, ideas. Thanks. Code below:

Code: Select all
inputMultiplexer.addProcessor(stage);
inputMultiplexer.addProcessor(new GestureDetector(gestureInputListener));
Gdx.input.setInputProcessor(inputMultiplexer);


P.S: if I try returning false in my stage(button listeners) then my character keeps moving and he won't stop.
Last edited by jos_fzr on Wed Sep 04, 2013 8:32 pm, edited 2 times in total.
jos_fzr
 
Posts: 3
Joined: Thu Aug 15, 2013 5:24 pm

Re: GestureDetector.GestureListener and InputListener in lib

Postby Mackhdo » Wed Sep 04, 2013 6:19 pm

Hi,

I can only help you with the part InputListener and GestureDetector working at the same time.

I did it this way :

Code: Select all
public class GameScreen implements Screen, GestureListener, InputProcessor {

   @Override
   public void show() {
      InputMultiplexer multiplexer = new InputMultiplexer();
      multiplexer.addProcessor(new GestureDetector(this));
      multiplexer.addProcessor(this);
      Gdx.input.setInputProcessor(multiplexer);
   }

   @Override
   public void hide() {
      Gdx.input.setInputProcessor(null);
   }

   @Override
   public boolean fling(float velocityX, float velocityY, int button) {
      return false;
   }

       // and all others events
}


This way you have access to all the events of both.

Hope that helps.
Mackhdo
 
Posts: 3
Joined: Tue Sep 03, 2013 4:52 pm

Re: GestureDetector.GestureListener and InputListener in lib

Postby jos_fzr » Wed Sep 04, 2013 8:34 pm

Mackhdo wrote:Hi,

I can only help you with the part InputListener and GestureDetector working at the same time.

I did it this way :

Code: Select all
public class GameScreen implements Screen, GestureListener, InputProcessor {

   @Override
   public void show() {
      InputMultiplexer multiplexer = new InputMultiplexer();
      multiplexer.addProcessor(new GestureDetector(this));
      multiplexer.addProcessor(this);
      Gdx.input.setInputProcessor(multiplexer);
   }

   @Override
   public void hide() {
      Gdx.input.setInputProcessor(null);
   }

   @Override
   public boolean fling(float velocityX, float velocityY, int button) {
      return false;
   }

       // and all others events
}


This way you have access to all the events of both.

Hope that helps.


but what if my inputListener is used on a button in a table in stage? what do I do then?
jos_fzr
 
Posts: 3
Joined: Thu Aug 15, 2013 5:24 pm

Re: GestureListener and InputListener in libgdx

Postby villegas_j » Fri Nov 23, 2018 10:19 pm

I did mine like this:

Code: Select all

public class GameScreen implements Screen, GestureListener, InputProcessor {

   @Override
   public void show() {
        GestureDetector gd = new GestureDetector(this);
        multiplexer.addProcessor(gd);
        multiplexer.addProcessor(UIstage); // UI
        multiplexer.addProcessor(this); //move camera
        multiplexer.addProcessor(stage); // actor on game
   }

   @Override
   public void hide() {
      Gdx.input.setInputProcessor(null);
   }

   @Override
   public boolean fling(float velocityX, float velocityY, int button) {
      return false;
   }

       // and all others events
}


       
villegas_j
 
Posts: 24
Joined: Tue Feb 17, 2015 8:54 pm


Return to Android Game Development Workshop

Who is online

Users browsing this forum: No registered users and 1 guest