Example usage for com.badlogic.gdx.math Matrix4 setToOrtho2D

List of usage examples for com.badlogic.gdx.math Matrix4 setToOrtho2D

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Matrix4 setToOrtho2D.

Prototype

public Matrix4 setToOrtho2D(float x, float y, float width, float height) 

Source Link

Document

Sets this matrix to an orthographic projection matrix with the origin at (x,y) extending by width and height.

Usage

From source file:com.andgate.pokeadot.PokeADot.java

License:Open Source License

public void screenAdjustments(int width, int height) {
    ppm = (float) height / worldHeight;
    worldWidth = worldHeight * (float) width / (float) height;

    Matrix4 matrix = new Matrix4();
    matrix.setToOrtho2D(0, 0, width, height);
    batch.setProjectionMatrix(matrix);//from  w w w  .ja  va2  s  .com
}

From source file:com.sixteencolorgames.sandbox.GameScreen.java

@Override
public void render(float delta) {
    super.render(delta);
    camera.update();//from   w w w. j a v a  2  s .c  o  m

    game.shape.setProjectionMatrix(camera.combined);
    game.batch.setProjectionMatrix(camera.combined);
    game.batch.begin();
    elapsedTime += Gdx.graphics.getDeltaTime();
    world.render();
    //        game.batch.draw(game.textures.get("startgame"), startGame.x, startGame.y,
    //                startGame.width, startGame.height);

    game.batch.end();
    //        game.shape.begin(ShapeRenderer.ShapeType.Line);
    //        game.shape.setColor(Color.CYAN);
    //        for (Waypoint point : dun.graph.getWaypoints()) {
    //            try {
    //                game.shape.line(point.getGridPosition().cpy().scl(SCALE).add(
    //                        SCALE / 2, SCALE / 2),
    //                        point.getPrevious().getGridPosition().cpy().scl(SCALE).add(
    //                                SCALE / 2, SCALE / 2));
    //            } catch (Exception ex) {
    //            }
    //        }
    //        game.shape.end();
    Matrix4 uiMatrix = camera.combined.cpy();
    uiMatrix.setToOrtho2D(0, 0, WIDTH, HEIGHT);
    game.batch.setProjectionMatrix(uiMatrix);
    game.batch.begin();
    game.batch.setColor(1, 1, 1, .5f);
    renderHUD();
    game.batch.setColor(1, 1, 1, 1);
    game.batch.end();

    if (Gdx.input.isKeyPressed(Keys.RIGHT)) {
        this.moveCameraPosition(new Vector2(2, 0));
        if (camera.position.x / 16 > world.getWidth()) {
            this.setCameraPosition(new Vector2(0, camera.position.y));
        }
    } else if (Gdx.input.isKeyPressed(Keys.LEFT)) {
        this.moveCameraPosition(new Vector2(-2, 0));
        if (camera.position.x / 16 < 0) {
            this.setCameraPosition(new Vector2(world.getWidth() * 16, camera.position.y));
        }
    }

}

From source file:it.alcacoop.fourinaline.actors.BoardImage.java

License:Open Source License

public void layout() {
    if (drawable == null)
        return;//from ww w.j av a 2  s  . c  o m

    float regionWidth = drawable.getMinWidth();
    float regionHeight = drawable.getMinHeight();
    float width = getWidth();
    float height = getHeight();

    Vector2 size = scaling.apply(regionWidth, regionHeight, width, height);
    imageWidth = size.x;
    imageHeight = size.y;

    if ((align & Align.left) != 0)
        imageX = 0;
    else if ((align & Align.right) != 0)
        imageX = (int) (width - imageWidth);
    else
        imageX = (int) (width / 2 - imageWidth / 2);

    if ((align & Align.top) != 0)
        imageY = (int) (height - imageHeight);
    else if ((align & Align.bottom) != 0)
        imageY = 0;
    else
        imageY = (int) (height / 2 - imageHeight / 2);

    if (fbo1 == null) {
        fbo1 = new FrameBuffer(Format.RGBA8888, (int) getWidth(), (int) getHeight(), false);
        fbo2 = new FrameBuffer(Format.RGBA8888, (int) getWidth(), (int) getHeight(), false);
    }

    SpriteBatch sb = new SpriteBatch();
    Matrix4 matrix = new Matrix4();
    matrix.setToOrtho2D(0, 0, getWidth(), getHeight()); // here is the actual size you want
    sb.setProjectionMatrix(matrix);

    fbo1.begin();
    sb.begin();
    Gdx.gl.glClearColor(1, 1, 1, 0);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    if (drawable != null) {
        for (int x = 0; x < nx; x++)
            for (int y = 0; y < ny; y++) {
                sb.draw(mask, x * xdim, y * ydim, 0, 0, xdim, ydim, 1, 1, 0);
            }
    }
    sb.end();
    fbo1.end();

    fbo2.begin();
    sb.setShader(shader);
    sb.begin();
    Gdx.gl.glClearColor(1, 1, 1, 0);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE1);
    wood.bind();
    shader.setUniformi("u_wood", 1);

    Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE0);
    sb.draw(fbo1.getColorBufferTexture(), 0, 0, getWidth(), getHeight());
    sb.end();
    shader.end();
    sb.setShader(null);
    fbo2.end();
}

From source file:it.alcacoop.fourinaline.actors.Checker.java

License:Open Source License

public Checker() {
    super();/* ww w  .  ja  v  a 2 s .  co m*/
    r1 = FourInALine.Instance.atlas.findRegion("CSW");
    r2 = FourInALine.Instance.atlas.findRegion("CSB");

    shader = new ShaderProgram(Gdx.files.internal("shaders/vertex.s"),
            Gdx.files.internal("shaders/fragment2.s"));
    System.out.println(shader.isCompiled());
    System.out.println(shader.getLog());
    wood = FourInALine.Instance.wood;
    rnd = new Random();

    fbo = new FrameBuffer(Format.RGBA4444, r1.getRegionWidth(), r1.getRegionHeight(), true);
    sb = new SpriteBatch();
    Matrix4 matrix = new Matrix4();
    matrix.setToOrtho2D(0, 0, r1.getRegionWidth(), r1.getRegionHeight());
    sb.setProjectionMatrix(matrix);
    setColor(1);
}

From source file:pl.kotcrab.gdxcombat.GameScene.java

License:Apache License

public GameScene(AbstractArena arena, AbstractFighter player, AbstractFighter enemy) {
    this.arena = arena;
    this.player = player;
    this.enemy = enemy;

    world = new World(new Vector2(0, -20), true);

    camera = Touch.getCamera();//  ww w. j  a  v  a  2  s . c  o m

    Matrix4 hudMatrix = new Matrix4();
    hudMatrix.setToOrtho2D(0, 0, 480, 320);
    hudBatch = new SpriteBatch();
    hudBatch.setProjectionMatrix(hudMatrix);

    fightTextAnim = new Animation(0.03f, AnimationUtils.loadAnim(Assets.getTextureAtlas(), "fight", 21));
    startTime = System.currentTimeMillis();

    player.setPosition(30, 150 - player.getHeight());
    enemy.setPosition(350, 150 - enemy.getHeight());

    player.setGroundLevel(arena.getGroundLevel());
    enemy.setGroundLevel(arena.getGroundLevel());

    player.setOponent(enemy);
    enemy.setOponent(player);

    enemy.initAi(new RandomBot());

    arena.initPhys(world);
    player.initPhys(world);
    enemy.initPhys(world);

    createHUD();

    debugRenderer = new Box2DDebugRenderer();
    box2dRenderMatrix = new Matrix4();

    Assets.fight.play();
}