Multitouch handling in libgdx

ok, so I tried to implement a multitouch solution for my libgdx game and am experiencing certain problems. Basically, I have a dpad in the lower left quadrant of the screen, which controls the direction of my character, and on the remaing part of the screen, I need to process swipes so that the character jumps, hits or throws something to the opponent. I originally considered using fling in a GestureListener. However, since then I have been informed that fling is not supported in multitouch and since then has begun to use pan to detect swipes. The problem I'm currently facing is that if I have a finger on the screen when using a swipe (the player moves and tries to jump), the pointer passed to the panorama seems wrong (at least on my logging and understanding the implementation) in any case, the code is below, and the link to the docs on the gesture detector here , if someone can help explain what is happening, would be greatly appreciated.

@Override public boolean touchDown(float x, float y, int pointer, int button) { if (x < width / 3 && y > height / 2) { directionPointer= pointer; if(x< width/6){ controller.leftPressed(); message=" driection TOUCH DOWN POINTER IS: " + pointer + "the action pointer -> " +actionPointer +"directionPointer->"+ directionPointer; Gdx.app.log("INFO", message); return true; }else{oller.rightPressed(); message=" direction TOUCH DOWN POINTER IS: " + pointer + "the action pointer -> " +actionPointer +"directionPointer->"+ directionPointer; Gdx.app.log("INFO", message); return true; } }else{ actionPointer= pointer; down_x=x; down_y=y; message= "Pointer value is" + actionPointer; } message="TOUCH DOWN POINTER IS: " + pointer + "the action pointer -> " +actionPointer +"directionPointer->"+ directionPointer; Gdx.app.log("INFO", message); return false; } @Override public boolean touchUp(int x, int y, int pointer, int button) { if ( pointer == directionPointer) { controller.leftReleased(); controller.rightReleased(); directionPointer=-1; return true; } if (x < width / 3 && y > height / 2) { controller.leftReleased(); controller.rightReleased(); directionPointer=-1; message= "TOUCHUP pointer is ->"+ pointer + "actionPointer->"+ actionPointer + "directionPointer-> "+ directionPointer; Gdx.app.log("INFO", message); return true; } message= "touchUP was detected"; Gdx.app.log("INFO", message); return false; } @Override public boolean panStop(float x, float y, int pointer, int button) { message="swipe not processed"; if( pointer==actionPointer){ delta_x= Math.abs(down_x -x); delta_y= Math.abs(down_y - y); if (delta_x < delta_y ){ // this is an up or down value if(down_x > x){ controller.bobPunch(); message = "SWIPE DOWNWARD " ; }else { // swipe up controller.bobJump(); message = "SWIPE UPWARD " ; } }else{ if(down_y< y){ controller.throwPressed(); message=" SWIPE RIGHT"; //swipe right ward }else{ controller.throwPressed(); message=" SWIPE LEFT"; // swipe left } } } Gdx.app.log("INFO", message); message="panstop pointer is : " + pointer + "the action pointer-> " +actionPointer + "directionPointer->" + directionPointer; Gdx.app.log("INFO", message); actionPointer=-1; // TODO Auto-generated method stub return true; } 

now this is the appropriate code to determine what actions should be taken (directionPointer and actionPointer are initialized ad ad int -1 declarations), the problem is that the pointer returned by panStop is not what I expected, these are some log output files for various touch actions to show what is happening:

case 1: hold the bottom left corner of the screen (bob moves to the left):

 direction TOUCHdOWN POINTER IS: 0 action pointer->-1 directionpointer->0 

case2 swipe up (jumping bob)

 TOUCHdOWN POINTER IS: 0 action pointer->0 directionpointer->-1 SWIPE UPWARD panstop pointer is: 0 actionpointer->0 directionpointer->-1 

case 3 moves and jumps (this is where the problem is):

 direction TOUCHdOWN POINTER IS: 0 action pointer->-1 directionpointer->0 TOUCHdOWN POINTER IS: 1 action pointer->1 directionpointer->0 swipe not processed panstop pointer is: 0 actionpointer->1 directionpointer->0 

now the last line, although I can’t prove it to you, the problem is that the finger that I am viewing is registered as an action pointer, the direction indicator (which does not leave the screen) is the one that was returned. Can someone point out what I'm doing wrong, or if this is a bug with libgdx itself or, more likely, my code itself

`

+8
java android libgdx multi-touch
source share
1 answer

What you can actually do is let DPAD be an actor connected to the Stage, while the on-screen controls are processed in the InputProcessor or GestureListener and use the InputMultiplexer to combine them:

 InputMultiplexer im = new InputMultiplexer(stage, inputProcessor); Gdx.input.setInputProcessor(im); 

also, if I'm not mistaken, the order of the parameters sent to InputMultiplexer is considered a priority. This means that in the above case, the Stage (DPAD) will be prioritized before the controls on the screen. Therefore, in your case, you probably want to switch them.

I know that this may not be a good solution for you, but I did it in some of my games.

+1
source share

All Articles