Example usage for com.badlogic.gdx.graphics.g2d SpriteBatch setTransformMatrix

List of usage examples for com.badlogic.gdx.graphics.g2d SpriteBatch setTransformMatrix

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d SpriteBatch setTransformMatrix.

Prototype

@Override
    public void setTransformMatrix(Matrix4 transform) 

Source Link

Usage

From source file:com.bladecoder.engine.spine.SpineRenderer.java

License:Apache License

@Override
public void draw(SpriteBatch batch, float x, float y, float scale) {

    if (currentSource != null && currentSource.skeleton != null) {
        currentSource.skeleton.setX(x / scale);
        currentSource.skeleton.setY(y / scale);

        batch.setTransformMatrix(batch.getTransformMatrix().scale(scale, scale, 1.0f));
        renderer.draw(batch, currentSource.skeleton);
        batch.setTransformMatrix(batch.getTransformMatrix().scale(1 / scale, 1 / scale, 1.0f));
    } else {// ww  w.  j a v a 2  s .c  o m
        x = x - getWidth() / 2 * scale;
        RectangleRenderer.draw(batch, x, y, getWidth() * scale, getHeight() * scale, Color.RED);
    }
}

From source file:com.mygdx.game.debugdrawers.NavMeshDebugDrawer.java

License:Apache License

private void drawNavMeshIndices(SpriteBatch spriteBatch, Camera camera, BitmapFont font) {
    // TODO: Get rid of all the transform matrix setting
    if (spriteBatch.isDrawing()) {
        spriteBatch.end();//from  w ww.j  a va 2  s. c om
    }
    spriteBatch.begin();
    spriteBatch.setProjectionMatrix(camera.combined);
    for (int i = 0; i < navMesh.graph.getNodeCount(); i++) {
        Triangle t = navMesh.graph.getTriangleFromGraphIndex(i);
        if (triangleIsVisible(t)) {
            tmpMatrix.set(camera.view).inv().getRotation(tmpQuat);
            tmpMatrix.setToTranslation(t.centroid).rotate(tmpQuat);
            spriteBatch.setTransformMatrix(tmpMatrix);
            font.draw(spriteBatch, Integer.toString(t.triIndex), 0, 0);
        }
    }
    spriteBatch.end();
}

From source file:com.ridiculousRPG.animation.WeatherEffectLayer.java

License:Apache License

/**
 * Draw the effect-layer./*from ww w.j a  va 2  s .c  om*/
 */
public void draw(SpriteBatch batch, Camera cam, boolean debug) {
    if (flip) {
        batch.setTransformMatrix(compTransMatrix(batch, cam));
    }
    if (fadeAlpha < 1f) {
        Color c = batch.getColor();
        c.a *= fadeAlpha;
        batch.setColor(c);
        fadeAlpha += fadeBy * Gdx.graphics.getDeltaTime();
        if (fadeAlpha > 1f)
            fadeAlpha = 1f;
    }
    // load frequently used variables into registers
    Texture t = tRef.getTexture();
    int tWidth = tRef.getRegionWidth();
    int tHeight = tRef.getRegionHeight();
    float x1 = Math.max(0f, cam.position.x);
    float y1 = Math.max(0f, cam.position.y);
    float x2 = Math.min(width, x1 + cam.viewportWidth);
    float y2 = Math.min(height, y1 + cam.viewportHeight);
    float x3 = x1 - tWidth;
    float y3 = y1 - tHeight;
    float x4 = x2 - tWidth;
    float y4 = y2 - tHeight;

    for (List<Rectangle> row : tileLayer) {
        for (Rectangle clip : row) {
            float x = clip.x;
            float y = clip.y;
            if (x > x3 && y > y3 && x < x2 && y < y2) {
                // texel space origin is upper left corner (unlike screen
                // space)
                int srcX = 0;
                int srcY = 0;
                int srcWidth = tWidth;
                int srcHeight = tHeight;
                if (x < x1) {
                    srcX = (int) (x1 - x + .7f);
                    srcWidth -= srcX;
                    x += srcX;
                }
                if (x > x4) {
                    srcWidth -= x - x4;
                }
                if (y < y1) {
                    srcHeight -= y1 - y;
                    y = y1;
                }
                if (y > y4) {
                    srcY = (int) (y - y4);
                    srcHeight -= srcY;
                    y += y - y4 - srcY;
                }
                batch.draw(t, x, y, srcX, srcY, srcWidth, srcHeight);
            }
        }
    }
    if (flip) {
        batch.setTransformMatrix(batch.getTransformMatrix().idt());
    }
    /*
     * if (debug) { batch.end(); List<Rectangle> rects = new
     * ArrayList<Rectangle>(); for (List<Rectangle> row : tileLayer) for
     * (Rectangle clip : row) rects.add(new Rectangle(clip.x, clip.y,
     * Math.abs(tWidth), Math.abs(tHeight))); DebugHelper.debugRectangle(new
     * Color(1f, 0.67f, 0f, .4f), flip ? compTransMatrix(batch, cam) : null,
     * rects .toArray(new Rectangle[0])); batch.begin(); }
     */
}

From source file:com.ridiculousRPG.event.EventObject.java

License:Apache License

public void draw(SpriteBatch spriteBatch) {
    if (visible) {
        drawDoneSwitch = true;/*ww w . j av a 2 s.  com*/
        float eventColorBits = this.colorFloatBits;
        float gameColorBits = GameBase.$().getGameColorBits();
        if (gameColorBits != COLOR_WHITE_BITS) {
            if (eventColorBits != COLOR_WHITE_BITS) {
                Color c1 = this.color;
                Color c2 = GameBase.$().getGameColorTint();
                eventColorBits = Color.toFloatBits(c1.r * c2.r, c1.g * c2.g, c1.b * c2.b, c1.a * c2.a);
            } else {
                eventColorBits = gameColorBits;
            }
        }
        float x = drawBound.x;
        float y = drawBound.y;
        float h = drawBound.height;
        float w = drawBound.width;
        float oX = getOffsetX();
        float oY = getOffsetY();
        spriteBatch.setColor(eventColorBits);
        boolean trans = oX != 0 || oY != 0;
        if (trans)
            spriteBatch.setTransformMatrix(spriteBatch.getTransformMatrix().translate(oX, oY, 0));
        if (effectRear != null)
            effectRear.draw(spriteBatch);
        if (image != null)
            spriteBatch.draw(image, x, y, w * .5f, h * .5f, w, h, scaleX, scaleY, rotation);
        if (effectFront != null)
            effectFront.draw(spriteBatch);
        if (trans)
            spriteBatch.setTransformMatrix(spriteBatch.getTransformMatrix().translate(-oX, -oY, 0));
        spriteBatch.setColor(gameColorBits);
    }
}

From source file:kyle.game.besiege.location.Location.java

License:Open Source License

public void drawText(SpriteBatch batch) {
    float size_factor = 1.4f;

    if ((this.type == LocationType.VILLAGE))
        size_factor = .5f * size_factor;
    if ((this.type == LocationType.CASTLE))
        size_factor = .7f * size_factor;

    Color temp = batch.getColor();
    float zoom = getKingdom().getMapScreen().getCamera().zoom;
    zoom *= size_factor;/* w w  w .  j a  v a 2 s  .  com*/

    // TODO do some vector calculations to make this rotate   
    // TODO create a bunch more fonts for smoother scrolling!
    // TODO do this in Kingdom at the end of everything
    // don't draw village names at a certain point.
    if (!(this.type == LocationType.VILLAGE && zoom > 1.5) && !(this.type == LocationType.CASTLE && zoom > 3)) {
        BitmapFont font;

        if (zoom > 7) {
            font = Assets.pixel150;
            zoom = 7;
        } else if (zoom > 5) {
            font = Assets.pixel100;
            zoom = 5;
        } else if (zoom > 4) {
            font = Assets.pixel80;
            zoom = 4;
        } else if (zoom > 3) {
            font = Assets.pixel64;
            zoom = 3;
        }
        // add some fonts here for smoothness
        else if (zoom > 2.5) {
            font = Assets.pixel50;
            zoom = 2.5f;
        } else if (zoom > 2) {
            font = Assets.pixel40;
            zoom = 2f;
        } else if (zoom > 1.5) {
            font = Assets.pixel30;
            zoom = 1.5f;
        } else if (zoom > 1.2) {
            font = Assets.pixel24;
            zoom = 1.2f;
        } else if (zoom > 1) {
            font = Assets.pixel20;
            zoom = 1f;
        } else if (zoom > .75) {
            font = Assets.pixel15;
            zoom = .75f;
        } else {
            font = Assets.pixel12;
            zoom = .6f;
        }
        String toDraw = getName();

        Matrix4 mx4Font = new Matrix4();
        mx4Font.trn((getX() - (int) (4.3 * toDraw.length()) * zoom), (getY() - 5 - 5 * zoom), 0);
        mx4Font.setToRotation(new Vector3(0, 0, 1), getKingdom().getMapScreen().getRotation());
        Matrix4 tempMatrix = batch.getTransformMatrix();
        batch.setTransformMatrix(mx4Font);

        //         // draw crest
        Color clear_white = new Color();
        clear_white.b = 1;
        clear_white.r = 1;
        clear_white.g = 1;
        clear_white.a = .8f;
        //         batch.setColor(clear_white);
        //         batch.draw(this.getFaction().crest, getCenterX() - 14*zoom, getCenterY() + 13, 30*zoom, 45*zoom);
        //         batch.setColor(temp);

        // draw text
        font.setColor(clear_white);
        font.draw(batch, toDraw, getX() - (int) (4.3 * toDraw.length()) * zoom, getY() - 5 - 5 * zoom);

        batch.setTransformMatrix(tempMatrix);
    }
}

From source file:org.bladecoder.bladeengine.model.SpineRenderer.java

License:Apache License

@Override
public void draw(SpriteBatch batch, float x, float y, float scale) {

    if (currentSkeleton != null && currentSkeleton.skeleton != null) {
        currentSkeleton.skeleton.setX(x / scale);
        currentSkeleton.skeleton.setY(y / scale);

        batch.setTransformMatrix(batch.getTransformMatrix().scale(scale, scale, 1.0f));
        renderer.draw(batch, currentSkeleton.skeleton);
        batch.setTransformMatrix(batch.getTransformMatrix().scale(1 / scale, 1 / scale, 1.0f));
    } else {//from  w  w w  .ja v a2 s .c  om
        RectangleRenderer.draw(batch, x, y, getWidth() * scale, getHeight() * scale, Color.RED);
    }
}

From source file:org.matheusdev.ror.FollowingCamera.java

License:Open Source License

public void loadToBatch(SpriteBatch batch) {
    batch.setProjectionMatrix(cam.projection);
    batch.setTransformMatrix(cam.view);
}

From source file:org.matheusdev.ror.screens.ScreenGameMap.java

License:Open Source License

public void drawHUD(SpriteBatch batch) {
    // Update chat text:
    if (client.chatChanged())
        updateChat();// ww  w.  ja v  a 2s .  co  m
    // draw Stage:
    stage.draw();
    // Render the HUD:
    hudCam.update();
    batch.setProjectionMatrix(hudCam.projection);
    batch.setTransformMatrix(hudCam.view);
    batch.begin();
    float x = -Gdx.graphics.getWidth() / 2f + 5f;
    float y = Gdx.graphics.getHeight() / 2f - 5f;
    // The only thing on the HUD is the FPS:
    font.draw(batch, "fps: " + Gdx.graphics.getFramesPerSecond(), x, y);
    batch.end();
}

From source file:org.tntstudio.core.Screen.java

License:Apache License

@Override
public void vpApply(SpriteBatch batch) {
    if (batch == null)
        return;//from  w ww . j a va2s . c o m

    batch.setProjectionMatrix(projection);
    batch.setTransformMatrix(transform);
}

From source file:pl.kotcrab.gdxcombat.core.KotcrabText.java

License:Apache License

public void draw(SpriteBatch spriteBatch) //render tekstu
{
    oldMatrix = spriteBatch.getTransformMatrix().cpy(); //kopia matrixa

    spriteBatch.setTransformMatrix(newMatrix); //ustawienie nowego matrixa do tekstu

    bitmapFontCache.draw(spriteBatch); //redner tekstu

    spriteBatch.setTransformMatrix(oldMatrix); //przywrocenie matrixa
}