java - Box2d body not responding to inputs -


i'm using libgdx , box2d , want make player's body jump. nothing happens when try use methods if it's moving.

//gravity vector2 vector2 gravity = new vector2(0,-9.8); //box2d world world world = new world(gravity);  //then created player body public void createplayer(){     bodydef def = new bodydef();     def.type = bodydef.bodytype.dynamicbody;     def.fixedrotation = true;     def.position.set(80, 200);     player = world.createbody(def);      polygonshape shape = new polygonshape();     shape.setasbox(20, 20);     player.createfixture(shape, 1f);     shape.dispose(); }  //this jump method public void jump(){     if(gdx.input.justtouched() == true) {         player.applyforcetocenter(0, 900, false);         system.out.println("touched");//to make sure touch working`     } } 

nothing happens , player's body falls until collides static body, every time touch screen prints out "touched" string.

update

not sure if reason why it's not working, have 2 classes 1 rendering , 1 updating. on update class set world.step() , not directly class body is.

//class updating  public void update(float deltatime){     physics.world.step(1 / 60f, 6, 2);     physics.jump(); //calling jump method physics class } 

same thing rendering class, box2ddebugrenderer seperated bodies are

update

i fixed problem, physics class connected update , render class had reference create method of main class, don't understand because that's did constructor of other classes.

public void create(){     physics = new physics(); //object physics constructor. } 

the problem working box2d scale in meter box creating (20 meter x 20 meter) force of "300" not enough move work box2d need convert values

divide box2d value "wolrd_to_box" value scale

this post maybe helpful

libgdx box2d pixel meter conversion?

good luck

update :

try change

gdx.input.justtouched()  

to

gdx.input.istouched() 

because justtouched() method called once (not in continue way)


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -