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(TextureRegion region, float x, float y, float originX, float originY, float width,
            float height, float scaleX, float scaleY, float rotation, boolean clockwise) 

Source Link

Usage

From source file:com.binarytenshi.nopassing.core.environment.StreetHandler.java

public static void draw(SpriteBatch batch) {
    for (int x = 0; x < MapHandler.getMapSize().x; x++) {
        for (int y = 0; y < MapHandler.getMapSize().y; y++) {
            Sprite sprite = getSprite(x, y);

            if (highlight != null && highlight.x == x && highlight.y == y) {
                batch.setColor(1f, 1f, 1f, .5f);
                batch.draw(sprite, x * TextureLib.tileSide, y * TextureLib.tileSide, TextureLib.tileSide / 2,
                        TextureLib.tileSide / 2, TextureLib.tileSide, TextureLib.tileSide, 1f, 1f,
                        90 - sprite.getRotation(), true);
                batch.setColor(1f, 1f, 1f, 1f);
            }/*from w  ww  . j  av a  2 s  .  co m*/

            if (streetMap[x][y]) {
                batch.draw(sprite, x * TextureLib.tileSide, y * TextureLib.tileSide, TextureLib.tileSide / 2,
                        TextureLib.tileSide / 2, TextureLib.tileSide, TextureLib.tileSide, 1f, 1f,
                        90 - sprite.getRotation(), true);
            }
        }
    }
}

From source file:com.nuliy.example.Player.java

public void draw(SpriteBatch batch, float deltaTime) {
    if (dead == true) {
        frame = Assets.dying.getKeyFrame(time, false);
        batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                frame.getRegionWidth(), frame.getRegionHeight(), 1.4f, 0.65f, lastRot, true);
    }/* ww w. j ava  2s .c  o  m*/

    if (Assets.dying.getKeyFrame(time, false) == atlas.findRegion("dying2")) {
        time = 0;
    } else {
        time += deltaTime;
    }
    if (dead == false) {
        if (punch == false && shootM4 == false) {
            if (velocity.x > 0 && velocity.y == 0) {
                frame = Assets.runRight.getKeyFrame(time, true);
                batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                        frame.getRegionWidth(), frame.getRegionHeight(), 1, 1, 90, true);
                lastRot = 90;
            } else if (velocity.x < 0 && velocity.y == 0) {
                frame = Assets.runRight.getKeyFrame(time, true);
                batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                        frame.getRegionWidth(), frame.getRegionHeight(), 1, 1, 270, true);
                lastRot = 270;
            } else if (velocity.x == 0 && velocity.y > 0) {
                frame = Assets.runRight.getKeyFrame(time, true);
                batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                        frame.getRegionWidth(), frame.getRegionHeight(), 1, 1, 180, true);
                lastRot = 180;
            } else if (velocity.x > 0 && velocity.y > 0 && velocity.x == velocity.y) {
                frame = Assets.runRight.getKeyFrame(time, true);
                batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                        frame.getRegionWidth(), frame.getRegionHeight(), 1, 1, 135, true);
                lastRot = 135;
            } else if (velocity.x < 0 && velocity.y > 0 && -velocity.x == velocity.y) {
                frame = Assets.runRight.getKeyFrame(time, true);
                batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                        frame.getRegionWidth(), frame.getRegionHeight(), 1, 1, 225, true);
                lastRot = 225;
            } else if (velocity.x < 0 && velocity.y < 0 && velocity.x == velocity.y) {
                frame = Assets.runRight.getKeyFrame(time, true);
                batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                        frame.getRegionWidth(), frame.getRegionHeight(), 1, 1, 315, true);
                lastRot = 315;
            } else if (velocity.x == 0 && velocity.y < 0) {
                frame = Assets.runRight.getKeyFrame(time, true);
                batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                        frame.getRegionWidth(), frame.getRegionHeight(), 1, 1, 0, true);
                lastRot = 0;
            } else if (velocity.x > 0 && velocity.y < 0 && velocity.x == -velocity.y) {
                frame = Assets.runRight.getKeyFrame(time, true);
                batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                        frame.getRegionWidth(), frame.getRegionHeight(), 1, 1, 45, true);
                lastRot = 45;
            } else if (gunID == 0) {
                frame = Assets.stand;
                batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                        frame.getRegionWidth(), frame.getRegionHeight(), 1, 1, lastRot, true);
            } else if (gunID == 1) {
                frame = Assets.shootM4;
                batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                        frame.getRegionWidth(), frame.getRegionHeight(), 0.55f, 2.1f, lastRot, true);
            }
        } else if (punch == true) {
            if (lastRot == 90) {
                frame = Assets.playerPunch90.getKeyFrame(time, true);
                batch.draw(frame, bounds.x, bounds.y);
            } else if (lastRot == 180) {
                frame = Assets.playerPunch180.getKeyFrame(time, true);
                batch.draw(frame, bounds.x, bounds.y);
            } else if (lastRot == 270) {
                frame = Assets.playerPunch270.getKeyFrame(time, true);
                batch.draw(frame, bounds.x, bounds.y);
            } else if (lastRot == 360 || lastRot == 0) {
                frame = Assets.playerPunch360.getKeyFrame(time, true);
                batch.draw(frame, bounds.x, bounds.y);
            }
        } else if (shootM4 == true) {
            frame = Assets.flashM4;
            batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                    frame.getRegionWidth(), frame.getRegionHeight(), 0.55f, 2.2f, lastRot, true);
        }
    }
}

From source file:com.nuliy.example.Police.java

public void draw(SpriteBatch batch, Player p, float deltaTime) {
    if (velocity.x != 0 || velocity.y != 0) {
        time += deltaTime;/*from w  ww. ja  v  a  2  s  .com*/
    } else {
        time = 0;
    }
    frame = Assets.standCop;
    if (p.getWantedLvl() < 100) {
        if (velocity.x > 0 && velocity.y == 0) {
            frame = Assets.runCop.getKeyFrame(time, true);
            batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                    frame.getRegionWidth(), frame.getRegionHeight(), 1, 1, 90, true);
            lastRot = 90;
        } else if (velocity.x < 0 && velocity.y == 0) {
            frame = Assets.runCop.getKeyFrame(time, true);
            batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                    frame.getRegionWidth(), frame.getRegionHeight(), 1, 1, 270, true);
            lastRot = 270;
        } else if (velocity.x == 0 && velocity.y > 0) {
            frame = Assets.runCop.getKeyFrame(time, true);
            batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                    frame.getRegionWidth(), frame.getRegionHeight(), 1, 1, 180, true);
            lastRot = 180;
        } else if (velocity.x > 0 && velocity.y > 0 && velocity.x == velocity.y) {
            frame = Assets.runCop.getKeyFrame(time, true);
            batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                    frame.getRegionWidth(), frame.getRegionHeight(), 1, 1, 135, true);
            lastRot = 135;
        } else if (velocity.x < 0 && velocity.y > 0 && -velocity.x == velocity.y) {
            frame = Assets.runCop.getKeyFrame(time, true);
            batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                    frame.getRegionWidth(), frame.getRegionHeight(), 1, 1, 225, true);
            lastRot = 225;
        } else if (velocity.x < 0 && velocity.y < 0 && velocity.x == velocity.y) {
            frame = Assets.runCop.getKeyFrame(time, true);
            batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                    frame.getRegionWidth(), frame.getRegionHeight(), 1, 1, 315, true);
            lastRot = 315;
        } else if (velocity.x == 0 && velocity.y < 0) {
            frame = Assets.runCop.getKeyFrame(time, true);
            batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                    frame.getRegionWidth(), frame.getRegionHeight(), 1, 1, 0, true);
            lastRot = 0;
        } else if (velocity.x > 0 && velocity.y < 0 && velocity.x == -velocity.y) {
            frame = Assets.runCop.getKeyFrame(time, true);
            batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                    frame.getRegionWidth(), frame.getRegionHeight(), 1, 1, 45, true);
            lastRot = 45;
        } else {
            frame = Assets.standCop;
            batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                    frame.getRegionWidth(), frame.getRegionHeight(), 1, 1, 135, true);
            lastRot = 135;
        }
    } else {
        if (velocity.x > 0 && velocity.y == 0) {
            frame = Assets.policeM4.getKeyFrame(time, true);
            batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                    frame.getRegionWidth(), frame.getRegionHeight(), 0.55f, 2.2f, lastRot, true);
            lastRot = 90;
        } else if (velocity.x < 0 && velocity.y == 0) {
            frame = Assets.policeM4.getKeyFrame(time, true);
            batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                    frame.getRegionWidth(), frame.getRegionHeight(), 0.55f, 2.2f, lastRot, true);
            lastRot = 270;
        } else if (velocity.x == 0 && velocity.y > 0) {
            frame = Assets.policeM4.getKeyFrame(time, true);
            batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                    frame.getRegionWidth(), frame.getRegionHeight(), 0.55f, 2.2f, lastRot, true);
            lastRot = 180;
        } else if (velocity.x > 0 && velocity.y > 0 && velocity.x == velocity.y) {
            frame = Assets.policeM4.getKeyFrame(time, true);
            batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                    frame.getRegionWidth(), frame.getRegionHeight(), 0.55f, 2.2f, lastRot, true);
            lastRot = 135;
        } else if (velocity.x < 0 && velocity.y > 0 && -velocity.x == velocity.y) {
            frame = Assets.policeM4.getKeyFrame(time, true);
            batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                    frame.getRegionWidth(), frame.getRegionHeight(), 0.55f, 2.2f, lastRot, true);
            lastRot = 225;
        } else if (velocity.x < 0 && velocity.y < 0 && velocity.x == velocity.y) {
            frame = Assets.policeM4.getKeyFrame(time, true);
            batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                    frame.getRegionWidth(), frame.getRegionHeight(), 0.55f, 2.2f, lastRot, true);
            lastRot = 315;
        } else if (velocity.x == 0 && velocity.y < 0) {
            frame = Assets.policeM4.getKeyFrame(time, true);
            batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                    frame.getRegionWidth(), frame.getRegionHeight(), 0.55f, 2.2f, lastRot, true);
            lastRot = 0;
        } else if (velocity.x > 0 && velocity.y < 0 && velocity.x == -velocity.y) {
            frame = Assets.policeM4.getKeyFrame(time, true);
            batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                    frame.getRegionWidth(), frame.getRegionHeight(), 0.55f, 2.2f, lastRot, true);
            lastRot = 45;
        } else {
            frame = Assets.standPolice;
            batch.draw(frame, bounds.x, bounds.y, frame.getRegionWidth() / 2, frame.getRegionHeight() / 2,
                    frame.getRegionWidth(), frame.getRegionHeight(), 0.55f, 2.2f, lastRot, true);
        }
    }
}

From source file:com.octa.topdown.map.Tile.java

License:Open Source License

@Override
public void draw(SpriteBatch batch) {
    batch.draw(this.getTexture(), this.getX(), this.getY(), this.getWidth(), this.getHeight(),
            this.getRegionX(), this.getRegionY(), this.getRegionWidth(), this.getRegionHeight(), false, false);
}

From source file:org.ah.libgdx.components.Image.java

License:Open Source License

public void render(SpriteBatch spriteBatch) {
    Texture texture = getImageTexture();

    if (stretchImage) {
        spriteBatch.draw(texture, getX(), getY(), getWidth(), getHeight(), 0, 0, texture.getWidth(),
                texture.getHeight(), false, true);
    } else {//from w  ww.  ja va2 s. c  o m
        spriteBatch.draw(texture, getX() + (getWidth() - texture.getWidth()) / 2,
                getY() + (getHeight() - texture.getHeight()) / 2, texture.getWidth(), texture.getHeight(), 0, 0,
                texture.getWidth(), texture.getHeight(), false, true);
    }
}

From source file:org.csproduction.descendant.entities.Player.java

@Override
public void render(SpriteBatch sb) {
    TextureRegion frame = currentAnim.getFrame();
    int regionX = frame.getRegionX();
    int regionY = frame.getRegionY();
    int regionWidth = frame.getRegionWidth();
    int regionHeight = frame.getRegionHeight();

    sb.draw(frame.getTexture(), getX() - imageWidth / 2, getY() - 64 / 2 - 1, 64, 64, regionX, regionY,
            regionWidth, regionHeight, !facesRight, false);
}

From source file:org.csproduction.descendant.entities.spell.Spell.java

@Override
public void render(SpriteBatch sb) {
    TextureRegion frame = currentAnim.getFrame();
    int regionX = frame.getRegionX();
    int regionY = frame.getRegionY();
    int regionWidth = frame.getRegionWidth();
    int regionHeight = frame.getRegionHeight();

    sb.draw(frame.getTexture(), getX() - imageWidth / 2, getY() - imageHeight / 2, imageWidth, imageHeight,
            regionX, regionY, regionWidth, regionHeight, !facesRight, false);
}