/** Moves the camera by the given amount on each axis. * @param x the displacement on the x-axis * @param y the displacement on the y-axis */ public void translate (float x, float y) { translate(x, y, 0); }
/** Moves the camera by the given vector. * @param vec the displacement vector */ public void translate (Vector2 vec) { translate(vec.x, vec.y, 0); } }
/** Moves the camera by the given vector. * @param vec the displacement vector */ public void translate (Vector2 vec) { translate(vec.x, vec.y, 0); } }
/** Moves the camera by the given amount on each axis. * @param x the displacement on the x-axis * @param y the displacement on the y-axis */ public void translate (float x, float y) { translate(x, y, 0); }
/** Moves the camera by the given vector. * @param vec the displacement vector */ public void translate (Vector2 vec) { translate(vec.x, vec.y, 0); } }
/** Moves the camera by the given amount on each axis. * @param x the displacement on the x-axis * @param y the displacement on the y-axis */ public void translate (float x, float y) { translate(x, y, 0); }
public void translate(Vector2 delta) { // EditorLogger.debug("TRANSLATING - X: " + delta.x + " Y: " + delta.y); if (scn != null) { camera.translate(-delta.x, -delta.y, 0); camera.update(); } }
/** * Let's move the camera to focus on the green planet. First, we need to set the viewport size, * as we did with the star. Now we need to move the camera to the planet. * * A different way to do that is to move the camera to the origin, then translate it to the * position of the planet. */ private void trackPlanet(OrthographicCamera camera, float aspectRatio) { camera.viewportHeight = 2 * PLANET_RADIUS; camera.viewportWidth = aspectRatio * camera.viewportHeight; camera.position.set(0, 0, 0); camera.translate(PLANET_CENTER_X, PLANET_CENTER_Y, 0); }
/** * To get the camera to zoom out, so we can see the whole star, first we need to set the * camera's viewport size using setToOrtho. The first argument is whether we want increasing Y * to mean moving down. We don't, so we'll set it to false. The next two arguments are the * viewport width and height. The height just needs to be double the radius of the star, but if * we set the viewport width to be equal to the viewport height, the star will be a stretched * out oval, instead of a circle. * * This is because the aspect ratio (width / height) of the camera doesn't match the aspect * ratio of the screen. We can fix this by making our viewport wider, by multiplying twice the * star radius by the aspect ratio. * * If we stop there, it looks like our camera viewport is now big enough to hold the star, but * we're not looking at the right spot. In fact, it looks like the is centered in exactly the * same location as before. Let's set the camera's position to the center of the star. * * That looks pretty good, but now we've lost the planet. Let's use translate to nudge the * camera to the right, so we can see the planet again. */ private void trackStar(OrthographicCamera camera, float aspectRatio) { camera.viewportHeight = 2 * STAR_RADIUS; // This will stretch the star, since the aspect ratio doesn't match // camera.viewportWidth = 2 * STAR_RADIUS; camera.viewportWidth = aspectRatio * camera.viewportHeight; camera.position.set(STAR_CENTER_X, STAR_CENTER_Y, 0); camera.translate(STAR_RADIUS * (aspectRatio - 1), 0); }
public boolean keyDown(int keycode) { if (keycode == Input.Keys.LEFT) camera.translate(-32, 0); if (keycode == Input.Keys.RIGHT) camera.translate(32, 0); if (keycode == Input.Keys.UP) camera.translate(0, 32); if (keycode == Input.Keys.DOWN) camera.translate(0, -32); if (keycode == Input.Keys.NUM_1) tiledMap.getLayers().get(0).setVisible(!tiledMap.getLayers().get(0).isVisible());
@Override public boolean touchDragged(int screenX, int screenY, int pointer) { tmp.set(screenX, screenY, 0).sub(lastTouch).scl(-1, 1, 0).scl(cam.zoom); cam.translate(tmp); lastTouch.set(screenX, screenY, 0); return false; }
/** * Cleans up all translations, scaling and rotation */ private void undoTransformations() { if (rotation != 0f) { camera.rotateAround(new Vector3(rotationX, rotationY, 0), new Vector3(0, 0, 1), rotation); } camera.update(); if (translationX != 0f || translationY != 0f) { camera.translate(-translationX, -translationY); } camera.update(); }
@Override public boolean touchDragged(int x, int y, int pointer) { if (!Gdx.input.isButtonPressed(Buttons.RIGHT)) return false; Vector2 p = canvas.screenToWorld(x, y); Vector2 delta = new Vector2(p).sub(lastTouch); canvas.worldCamera.translate(-delta.x, -delta.y, 0); canvas.worldCamera.update(); lastTouch.set(canvas.screenToWorld(x, y)); return false; }
frmCam.translate(frmSizeX / 2, frmSizeY / 2);
frm = new TextureRegion(frmBuff.getColorBufferTexture()); frmCam= new OrthographicCamera(frmSizeX, frmSizeY); frmCam.translate(frmSizeX/2, frmSizeY/2);
/** * Applies all translation, scaling and rotation to the {@link SpriteBatch} */ private void applyTransformations() { float viewportWidth = MathUtils.round(windowWidth / scaleX); float viewportHeight = MathUtils.round(windowHeight / scaleY); camera.setToOrtho(true, viewportWidth, viewportHeight); if (translationX != 0f || translationY != 0f) { camera.translate(translationX, translationY); } camera.update(); if (rotation != 0f) { camera.rotateAround(new Vector3(rotationX, rotationY, 0), new Vector3(0, 0, 1), -rotation); } camera.update(); spriteBatch.setProjectionMatrix(camera.combined); shapeRenderer.setProjectionMatrix(camera.combined); polygonSpriteBatch.setProjectionMatrix(camera.combined); }