public void render(float delta) { Gdx.gl.glClearColor(0, 0, 0.2f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // tell the camera to update its matrices. camera.update( car.body.getPosition().x * PIXELS_PER_METER, car.body.getPosition().y * PIXELS_PER_METER); spriteBatch.setProjectionMatrix(camera.getCombined()); if (Gdx.input.isKeyPressed(Input.Keys.UP) || Gdx.input.isTouched()) { car.setAccelerate(Car.ACC_ACCELERATE); } else if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) { car.setAccelerate(Car.ACC_BRAKE); } else { car.setAccelerate(Car.ACC_NONE); } if (Gdx.input.isKeyPressed(Input.Keys.LEFT) || Gdx.input.getAccelerometerY() < -2.5) { car.setSteer(Car.STEER_HARD_LEFT); } else if (Gdx.input.getAccelerometerY() < -1) { car.setSteer(Car.STEER_LEFT); } else if (Gdx.input.isKeyPressed(Input.Keys.RIGHT) || Gdx.input.getAccelerometerY() > 2.5) { car.setSteer(Car.STEER_HARD_RIGHT); } else if (Gdx.input.getAccelerometerY() > 1) { car.setSteer(Car.STEER_RIGHT); } else { car.setSteer(Car.STEER_NONE); } car.update(Gdx.app.getGraphics().getDeltaTime()); /** * Have box2d update the positions and velocities (and etc) of all tracked objects. The second * and third argument specify the number of iterations of velocity and position tests to perform * -- higher is more accurate but is also slower. */ world.step(Gdx.app.getGraphics().getDeltaTime(), 3, 3); world.clearForces(); // draw the sprites spriteBatch.begin(); playerSprite.setPosition( PIXELS_PER_METER * car.body.getPosition().x - playerTexture.getRegionWidth() / 2, PIXELS_PER_METER * car.body.getPosition().y - playerTexture.getRegionHeight() / 2); playerSprite.setRotation((MathUtils.radiansToDegrees * car.body.getAngle())); playerSprite.setFlip(false, true); playerSprite.setScale(0.3f); playerSprite.draw(spriteBatch); spriteBatch.end(); /** Draw this last, so we can see the collision boundaries on top of the sprites and map. */ debugRenderer.render( world, camera.getCombined().scale(PIXELS_PER_METER, PIXELS_PER_METER, PIXELS_PER_METER)); }