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

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

Introduction

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

Prototype

@Override
    public void draw(Texture texture, float x, float y, int srcX, int srcY, int srcWidth, int srcHeight) 

Source Link

Usage

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

License:Apache License

/**
 * Draw the effect-layer.//from   ww w  . ja  v a 2  s . c o  m
 */
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:tk.makigas.chase.actor.BarraActor.java

License:Open Source License

@Override
public void draw(SpriteBatch batch, float parentAlpha) {
    batch.draw(barra, getX(), getY(), 0, 0, (int) (getWidth() * entidad.getHealth()), (int) getHeight());
}