Example usage for com.badlogic.gdx.graphics Camera translate

List of usage examples for com.badlogic.gdx.graphics Camera translate

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics Camera translate.

Prototype

public void translate(float x, float y, float z) 

Source Link

Document

Moves the camera by the given amount on each axis.

Usage

From source file:com.game.HelloWorld.java

License:Apache License

@Override
public void render() {

    GL10 gl = Gdx.graphics.getGL10();//from w w  w.j a  v a  2 s  . c om

    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    this.mCamera.apply(gl);
    this.mTileMapRenderer.render((OrthographicCamera) mRenderTree.getStage().getCamera());

    if (Gdx.input.isTouched() && !isCollision(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2)) {

        Vector3 position = new Vector3(mInputX, mInputY, 0);
        Camera camera = mRenderTree.getStage().getCamera();
        float deplacementX = (float) (directionPerso.x * mcharSpeed);
        float deplacementY = (float) (directionPerso.y * mcharSpeed);

        mRenderTree.getStage().findActor("mainChar").x += deplacementX;
        camera.translate(deplacementX, 0f, 0f);

        mRenderTree.getStage().findActor("mainChar").y += deplacementY;
        camera.translate(0f, deplacementY, 0f);

        if (deplacementX > 0.0f || deplacementY > 0.0f) {
            halfSec += Gdx.graphics.getDeltaTime();
            if (halfSec > 0.3f) {
                if (directionPerso.x >= 0.5) {
                    mSpriteN = 6 + (++mMainCharSpriteState) % 3;
                } else if (directionPerso.x <= -0.5) {
                    mSpriteN = 3 + (++mMainCharSpriteState) % 3;
                } else if (directionPerso.y >= 0.5) {
                    mSpriteN = 9 + (++mMainCharSpriteState) % 3;
                } else {
                    mSpriteN = (++mMainCharSpriteState) % 3;
                }
                halfSec = 0.0f;
            }
        }

        camera.update();
        camera.apply(gl);
    }

    //stage.draw();
    mRenderTree.draw();

    mMainCharBatch.begin();
    mMainCharBatch.draw(mMainCharRegions[mSpriteN], (Gdx.graphics.getWidth() / 2) - 16,
            (Gdx.graphics.getHeight() / 2) - 16, 32, 32);
    mMainCharBatch.end();

}

From source file:com.ridiculousRPG.camera.CameraTrackMovableService.java

License:Apache License

public void compute(float deltaTime, boolean pushButtonPressed) {
    if (trackObj == null)
        return;/*from w w  w .j av a 2s.  c o  m*/
    float newX = trackObj.getX();
    float newY = trackObj.getY();
    if (oldX != newX || oldY != newY) {
        Camera cam = GameBase.$().getCamera();
        cam.translate(newX - oldX, newY - oldY, 0f);
        cam.update();
        oldX = newX;
        oldY = newY;
    }
}

From source file:com.ridiculousRPG.camera.CameraZoomService.java

License:Apache License

/**
 * @param zoom//from   w w  w  .ja  v a2s . c  o m
 *            the new zoom value to set
 */
public void setZoom(float zoom) {
    Camera cam = GameBase.$().getCamera();
    float viewportWidth = cam.viewportWidth * zoom / this.zoom;
    float viewportHeight = cam.viewportHeight * zoom / this.zoom;
    float translateX = .5f * (cam.viewportWidth - viewportWidth);
    float translateY = .5f * (cam.viewportHeight - viewportHeight);
    cam.viewportWidth = viewportWidth;
    cam.viewportHeight = viewportHeight;
    cam.translate(translateX, translateY, 0);
    cam.update();
    this.zoom = zoom;
}

From source file:com.ridiculousRPG.camera.CameraZoomService.java

License:Apache License

/**
 * Zooms the camera by the given relative amount. An interval of 1 means no
 * zooming. If the interval is lower or equal zero, the camera will zoom to
 * normal zoom position (zoom is set to 1).
 * //from w ww  .j  av  a 2s  .  c  o  m
 * @param interval
 *            the relative zoom interval
 */
public void zoomBy(float interval) {
    if (interval <= 0) {
        setZoom(1f);
    } else {
        Camera cam = GameBase.$().getCamera();
        float viewportWidth = cam.viewportWidth * interval;
        float viewportHeight = cam.viewportHeight * interval;
        float translateX = .5f * (cam.viewportWidth - viewportWidth);
        float translateY = .5f * (cam.viewportHeight - viewportHeight);
        cam.viewportWidth = viewportWidth;
        cam.viewportHeight = viewportHeight;
        cam.translate(translateX, translateY, 0);
        cam.update();
        zoom *= interval;
    }
}

From source file:com.ridiculousRPG.GameBase.java

License:Apache License

@Override
public void resize(int width, int height) {
    Camera cam = camera;
    if (options.resize) {
        float centerX = cam.viewportWidth * .5f;
        float centerY = cam.viewportHeight * .5f;
        cam.viewportWidth *= width / screen.width;
        cam.viewportHeight *= height / screen.height;
        centerX -= cam.viewportWidth * .5f;
        centerY -= cam.viewportHeight * .5f;
        cam.translate(centerX, centerY, 0);
    }//from w  w  w. j  a v  a 2 s. c  om
    screen.width = width;
    screen.height = height;
    cam.update();
    serviceProvider.resize(width, height);
    if (!terminating)
        saveUserContext();
}

From source file:headmade.arttag.ArtTagInputController.java

License:Apache License

@Override
public boolean keyDown(int keycode) {
    final float movementSpeed = 10f;
    if (keycode == Keys.LEFT || keycode == Keys.A) {
        Player.instance.isMoveLeft = true;
        return true;
    } else if (keycode == Keys.RIGHT || keycode == Keys.D) {
        Player.instance.isMoveRight = true;
        return true;
    } else if (keycode == Keys.UP || keycode == Keys.W) {
        Player.instance.isMoveUp = true;
        return true;
    } else if (keycode == Keys.DOWN || keycode == Keys.S) {
        Player.instance.isMoveDown = true;
        return true;
    } else if (keycode == Keys.ALT_LEFT || keycode == Keys.ALT_RIGHT || keycode == Keys.Z
            || keycode == Keys.SPACE) {//  w  ww  .ja  v a 2  s .  c  om
        // action button 1
        // if (ArtTag.TOGGLE_LIGHT) {
        // Player.instance.isLightOn = !Player.instance.isLightOn;
        // } else {
        // Player.instance.isLightOn = true;
        // }
        // action button 2
        if (Player.instance.isAbleToSteal) {
            Player.instance.steal(artTagScreen);
            return true;
        } else if (Player.instance.isAbleToScan) {
            Player.instance.scan(artTagScreen);
            return true;
        } else if (Player.instance.isTouchingExit) {
            if (Player.instance.isExitActivated) {
                artTagScreen.endLevel();
            } else {
                Player.instance.activateExit(artTagScreen);
            }
            Player.instance.scan(artTagScreen);
            return true;
        }
        return true;
    } else if (keycode == Keys.CONTROL_LEFT || keycode == Keys.CONTROL_RIGHT || keycode == Keys.X
            || keycode == Keys.SHIFT_LEFT || keycode == Keys.SHIFT_RIGHT) {

        // default action
        Player.instance.isRunning = true;
        return true;
    } else if (keycode == Keys.F12) {
        artTagScreen.debugEnabled = !artTagScreen.debugEnabled;
        return true;
    }
    if (artTagScreen.debugEnabled) {
        // debug inputs
        if (keycode == Keys.SPACE) {
            artTagScreen.newJob();
            return true;
        } else if (keycode == Keys.J) {
            final Camera cam = artTagScreen.camera;
            cam.translate(-1 * movementSpeed, 0, 0);
            cam.update();
            return true;
        } else if (keycode == Keys.L) {
            final Camera cam = artTagScreen.camera;
            cam.translate(1 * movementSpeed, 0, 0);
            cam.update();
            return true;
        } else if (keycode == Keys.I) {
            final Camera cam = artTagScreen.camera;
            cam.translate(0, 1 * movementSpeed, 0);
            cam.update();
            return true;
        } else if (keycode == Keys.K) {
            final Camera cam = artTagScreen.camera;
            cam.translate(1, -1 * movementSpeed, 0);
            cam.update();
            return true;
        }
    }
    return super.keyDown(keycode);
}