SHARE
TWEET

Untitled

a guest Oct 18th, 2015 4 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Override
  2.         public void render() {
  3.  
  4.                 Gdx.gl.glClearColor(0, 0, 0, 1);
  5.                 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  6.                 if (Gdx.input.isKeyPressed(Input.Keys.W)) {
  7.                         playerBody.applyForceToCenter(50, 0, true);
  8.                 }
  9.                 else if (Gdx.input.isKeyPressed(Input.Keys.S)) {
  10.                         playerBody.applyForceToCenter(-50, 0, true);
  11.                 }
  12.                 world.step(Gdx.graphics.getDeltaTime(), 8, 3);
  13.                 camera.position.set(playerBody.getPosition().x, 7, 0);
  14.                 camera.update();
  15.                 mapRenderer.render();
  16.                 mapRenderer.setView(camera);
  17.                 draw();
  18.         }
  19.  
  20.         private void draw() {
  21.                 batch.setProjectionMatrix(camera.combined);
  22.                 batch.begin();
  23.                 world.getBodies(tmpBodies);
  24.                 for(Body body : tmpBodies) { // loops through (10) bodies and if userdata is sprite then draw the sprite at body pos.
  25.                         if (body.getUserData() != null && body.getUserData() instanceof Sprite) {
  26.                                 Sprite sprite = (Sprite) body.getUserData();
  27.                                 sprite.setPosition(body.getPosition().x - sprite.getWidth() / 2, body.getPosition().y - sprite.getHeight() / 2);
  28.                                 sprite.setRotation(body.getAngle() * MathUtils.radiansToDegrees);
  29.                                 sprite.draw(batch);
  30.                         }
  31.                 }
  32.                 batch.end();
  33.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top