Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- boolean change = false;
- if (Gdx.input.isKeyPressed(Input.Keys.A)) {
- cam.zoom += 0.02;
- change = true;
- }
- if (Gdx.input.isKeyPressed(Input.Keys.Q)) {
- cam.zoom -= 0.02;
- change = true;
- }
- if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
- cam.translate(-3, 0, 0);
- change = true;
- }
- if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
- cam.translate(3, 0, 0);
- change = true;
- }
- if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
- cam.translate(0, -3, 0);
- change = true;
- }
- if (Gdx.input.isKeyPressed(Input.Keys.UP)) {
- cam.translate(0, 3, 0);
- change = true;
- }
- if (Gdx.input.isKeyPressed(Input.Keys.W)) {
- cam.rotate(-rotationSpeed, 0, 0, 1);
- change = true;
- }
- if (Gdx.input.isKeyPressed(Input.Keys.E)) {
- cam.rotate(rotationSpeed, 0, 0, 1);
- change = true;
- }
- if(change) {
- cam.zoom = MathUtils.clamp(cam.zoom, 0.1f, 100 / cam.viewportWidth);
- float effectiveViewportWidth = cam.viewportWidth * cam.zoom;
- float effectiveViewportHeight = cam.viewportHeight * cam.zoom;
- cam.position.x = MathUtils.clamp(cam.position.x, effectiveViewportWidth / 2f, 100 - effectiveViewportWidth / 2f);
- cam.position.y = MathUtils.clamp(cam.position.y, effectiveViewportHeight / 2f, 100 - effectiveViewportHeight / 2f);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement