Ground not working...

Discuss issues specific the Java port of Box2D
deavisdude
Posts: 1
Joined: Sat May 03, 2014 11:19 am

Ground not working...

Postby deavisdude » Sat May 03, 2014 11:28 am

So, I am new to box2d and game development in general, I have created a body for my character, which is working fine, but when I attempt to create the body for the ground it compiles, runs, but does not actually affect the player as he falls into oblivion. here is where I create the ground:

Code: Select all

BodyDef bd = new BodyDef();
      bd.position.set(0.0f, groundY/DodgePong.pxPerMeter);
      bd.setType(BodyType.STATIC);
      EdgeShape es = new EdgeShape();
      es.setRadius(DodgePong.appgc.getWidth()/DodgePong.pxPerMeter);
      FixtureDef fd = new FixtureDef();
      fd.setShape(es);
      fd.setFriction(0.5f);
      Body ground = world.createBody(bd);
      ground.createFixture(fd);

groundY is the pixel value of where the ground level is. Something is wrong with the position I think, because in the game loop I try to print out the position of the ground and just get a null pointer exception...

Return to “Java”



Who is online

Users browsing this forum: Google [Bot] and 2 guests