Java Code Examples for com.badlogic.gdx.graphics.g2d.Batch#setTransformMatrix()

The following examples show how to use com.badlogic.gdx.graphics.g2d.Batch#setTransformMatrix() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpinEffectFactory.java    From Klooni1010 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void draw(Batch batch) {
    age += Gdx.graphics.getDeltaTime();

    final float progress = age * INV_LIFETIME;
    final float currentSize = Interpolation.pow2In.apply(size, 0, progress);
    final float currentRotation = Interpolation.sine.apply(0, TOTAL_ROTATION, progress);

    final Matrix4 original = batch.getTransformMatrix().cpy();
    final Matrix4 rotated = batch.getTransformMatrix();

    final float disp =
            +0.5f * (size - currentSize) // the smaller, the more we need to "push" to center
                    + currentSize * 0.5f; // center the cell for rotation

    rotated.translate(pos.x + disp, pos.y + disp, 0);
    rotated.rotate(0, 0, 1, currentRotation);
    rotated.translate(currentSize * -0.5f, currentSize * -0.5f, 0); // revert centering for rotation

    batch.setTransformMatrix(rotated);
    Cell.draw(color, batch, 0, 0, currentSize);
    batch.setTransformMatrix(original);
}
 
Example 2
Source File: Board.java    From Klooni1010 with GNU General Public License v3.0 5 votes vote down vote up
public void draw(final Batch batch) {
    batch.setTransformMatrix(batch.getTransformMatrix().translate(pos.x, pos.y, 0));

    for (int i = 0; i < cellCount; ++i)
        for (int j = 0; j < cellCount; ++j)
            cells[i][j].draw(batch);

    for (int i = effects.size; i-- != 0; ) {
        effects.get(i).draw(batch);
        if (effects.get(i).isDone())
            effects.removeIndex(i);
    }

    batch.setTransformMatrix(batch.getTransformMatrix().translate(-pos.x, -pos.y, 0));
}
 
Example 3
Source File: ViewportWidget.java    From talos with Apache License 2.0 4 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
    batch.end();

    localToScreenCoordinates(temp.set(0, 0));
    int x = (int)temp.x;
    int y = (int)temp.y;

    localToScreenCoordinates(temp.set(getWidth(), getHeight()));

    int x2 = (int)temp.x;
    int y2 = (int)temp.y;

    int ssWidth = x2 - x;
    int ssHeight = y - y2;

    HdpiUtils.glViewport(x, Gdx.graphics.getHeight() - y, ssWidth, ssHeight);

    Gdx.gl.glClearColor(bgColor.r, bgColor.g, bgColor.b, 1f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    float aspect = getWidth()/getHeight();

    camera.viewportHeight = camera.viewportWidth / aspect;

    camera.update();

    prevTransform.set(batch.getTransformMatrix());
    prevProjection.set(batch.getProjectionMatrix());
    batch.setProjectionMatrix(camera.combined);
    batch.setTransformMatrix(emptyTransform);

    batch.begin();
    drawContent(batch, parentAlpha);
    batch.end();

    HdpiUtils.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    batch.setProjectionMatrix(prevProjection);
    batch.setTransformMatrix(prevTransform);
    batch.begin();

    super.draw(batch, parentAlpha);
}