button - Implementing multiple inputs in libgdx -


i working on controls in libgdx. have 3 buttons: up, right , left. things working fine if click buttons separately.

on clicking 2 buttons simultaneously, e.g. right , buttons, player isn't having smooth jump . gets struck , not rendering .

part of code:

//up button buttonup.addlistener(new inputlistener() {     @override     public boolean touchdown(inputevent event, float x, float y, int pointer, int button) {          gamehero.herobody.setlinearvelocity(0, 4f);          return true;     } });  //right button buttonright.addlistener(new inputlistener() {      @override     public boolean touchdown(inputevent event, float x, float y, int pointer, int button){          gamehero.herobody.setlinearvelocity(2f, 0);         return true;     }      @override     public void touchup(inputevent event, float x, float y, int pointer, int button) {          gamehero.herobody.setlinearvelocity(0, 0);     } });  //left button buttonleft.addlistener(new inputlistener() {      @override     public boolean touchdown(inputevent event, float x, float y, int pointer, int button) {          if gamehero.herobody.setlinearvelocity(-2f, 0);             return true;     }      @override     public void touchup(inputevent event, float x, float y, int pointer, int button) {          gamehero.herobody.setlinearvelocity(0, 0);      } }); 

i have gone through many posts this didn't me. feel has done pointers don't know how use buttons. there way make player have smooth rendering if touch 2 buttons @ same time?

each button should affect motion in 1 of coordinate directions: x left/right, y up. rather setting velocity in other direction 0, should leave unchanged (i.e. set current value presumably stored in gamehero).

e.g. button should set like:

gamehero.herobody.setlinearvelocity(gamehero.velocity.x, 4f); 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

json - Gson().fromJson(jsonResult, Myobject.class) return values in 0's -