SHARE
TWEET
Untitled
a guest
Oct 18th, 2015
4
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- @Override
- public void render() {
- Gdx.gl.glClearColor(0, 0, 0, 1);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- if (Gdx.input.isKeyPressed(Input.Keys.W)) {
- playerBody.applyForceToCenter(50, 0, true);
- }
- else if (Gdx.input.isKeyPressed(Input.Keys.S)) {
- playerBody.applyForceToCenter(-50, 0, true);
- }
- world.step(Gdx.graphics.getDeltaTime(), 8, 3);
- camera.position.set(playerBody.getPosition().x, 7, 0);
- camera.update();
- mapRenderer.render();
- mapRenderer.setView(camera);
- draw();
- }
- private void draw() {
- batch.setProjectionMatrix(camera.combined);
- batch.begin();
- world.getBodies(tmpBodies);
- for(Body body : tmpBodies) { // loops through (10) bodies and if userdata is sprite then draw the sprite at body pos.
- if (body.getUserData() != null && body.getUserData() instanceof Sprite) {
- Sprite sprite = (Sprite) body.getUserData();
- sprite.setPosition(body.getPosition().x - sprite.getWidth() / 2, body.getPosition().y - sprite.getHeight() / 2);
- sprite.setRotation(body.getAngle() * MathUtils.radiansToDegrees);
- sprite.draw(batch);
- }
- }
- batch.end();
- }
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.

