Example usage for com.badlogic.gdx.graphics.g2d Sprite Sprite

List of usage examples for com.badlogic.gdx.graphics.g2d Sprite Sprite

Introduction

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

Prototype

public Sprite(TextureRegion region, int srcX, int srcY, int srcWidth, int srcHeight) 

Source Link

Document

Creates a sprite with width, height, and texture region equal to the specified size, relative to specified sprite's texture region.

Usage

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

private static Sprite getSprite(int x, int y) {
    Sprite sprite = new Sprite(streetTexture, 0, 0, TextureLib.tileSide, TextureLib.tileSide);

    // up, right, down, left (0b0000)
    byte orientation = getOrientation(x, y);

    switch (orientation) {
    // DEFAULT; UP DOWN
    case 0b0000://w w w  . j a  va 2s .c o  m
    case 0b1000:
    case 0b0010:
    case 0b1010:
        sprite.setRegion(0, 0, TextureLib.tileSide, TextureLib.tileSide);
        break;

    // LEFT RIGHT
    case 0b0101:
    case 0b0100:
    case 0b0001:
        sprite.setRegion(0, 0, TextureLib.tileSide, TextureLib.tileSide);
        sprite.setRotation(90f);
        break;

    // DOWN LEFT
    case 0b0011:
        sprite.setRegion(TextureLib.tileSide, 0, TextureLib.tileSide, TextureLib.tileSide);
        break;

    // RIGHT DOWN
    case 0b0110:
        sprite.setRegion(TextureLib.tileSide, 0, TextureLib.tileSide, TextureLib.tileSide);
        sprite.rotate(-90f);
        break;

    // UP RIGHT
    case 0b1100:
        sprite.setRegion(TextureLib.tileSide, 0, TextureLib.tileSide, TextureLib.tileSide);
        sprite.rotate(180f);
        break;

    // UP LEFT
    case 0b1001:
        sprite.setRegion(TextureLib.tileSide, 0, TextureLib.tileSide, TextureLib.tileSide);
        sprite.rotate(90f);
        break;

    // UP RIGHT DOWN
    case 0b1110:
        sprite.setRegion(0, TextureLib.tileSide, TextureLib.tileSide, TextureLib.tileSide);
        break;

    // UP RIGHT LEFT
    case 0b1101:
        sprite.setRegion(0, TextureLib.tileSide, TextureLib.tileSide, TextureLib.tileSide);
        sprite.rotate(-90f);
        break;

    // RIGHT DOWN LEFT
    case 0b0111:
        sprite.setRegion(0, TextureLib.tileSide, TextureLib.tileSide, TextureLib.tileSide);
        sprite.rotate(90f);
        break;

    // UP DOWN LEFT
    case 0b1011:
        sprite.setRegion(0, TextureLib.tileSide, TextureLib.tileSide, TextureLib.tileSide);
        sprite.rotate(180f);
        break;

    // UP RIGHT DOWN LEFT
    case 0b1111:
        sprite.setRegion(TextureLib.tileSide, TextureLib.tileSide, TextureLib.tileSide, TextureLib.tileSide);
        break;
    }

    return sprite;
}

From source file:com.digitale.mygdxgame.Renderer.java

License:Open Source License

private void bindTextures() {
    dustTexture = Stardust3d.manager.get("data/dust.png", Texture.class);
    blackpixelTexture = Stardust3d.manager.get("data/blackpixel.png", Texture.class);
    Stardust3d.manager.get("data/planet.jpg", Texture.class).setFilter(TextureFilter.Linear,
            TextureFilter.Linear);/*from  ww w. ja v  a2s  .c o  m*/
    planetTexture = Stardust3d.manager.get("data/planet.jpg", Texture.class);
    Stardust3d.manager.get("data/squirrel.png", Texture.class).setFilter(TextureFilter.Linear,
            TextureFilter.Linear);
    squirrelTexture = Stardust3d.manager.get("data/squirrel.png", Texture.class);
    planetTexture02 = Stardust3d.manager.get("data/planet02.jpg", Texture.class);
    Stardust3d.manager.get("data/sky01.jpg", Texture.class).setFilter(TextureFilter.Linear,
            TextureFilter.Linear);
    lvlupTexture = Stardust3d.manager.get("data/lvlup.jpg", Texture.class);
    skyTexture = Stardust3d.manager.get("data/sky01.jpg", Texture.class);
    shipTexture01 = Stardust3d.manager.get("data/destroyer01.png", Texture.class);
    Stardust3d.manager.get("data/nova.png", Texture.class);
    jetTexture = Stardust3d.manager.get("data/jet.png", Texture.class);
    moonTexture = Stardust3d.manager.get("data/craters.jpg", Texture.class);
    shipTexture02 = Stardust3d.manager.get("data/destroyer02.png", Texture.class);
    shipTexture03 = Stardust3d.manager.get("data/ship.png", Texture.class);
    hurtflash = Stardust3d.manager.get("data/hurtflash.png", Texture.class);
    swirlyTexture = Stardust3d.manager.get("data/swirlyglow.png", Texture.class);
    shieldDisruptorTexture = Stardust3d.manager.get("data/shielddisruptor.png", Texture.class);
    explosionTexture = Stardust3d.manager.get("data/explode.png", Texture.class);
    Stardust3d.manager.get("data/explodewave.png", Texture.class).setFilter(TextureFilter.Linear,
            TextureFilter.Linear);
    swansongTexture = Stardust3d.manager.get("data/explodewave.jpg", Texture.class);
    roidTexture = Stardust3d.manager.get("data/roid01tex.png", Texture.class);
    hangarTexture = Stardust3d.manager.get("data/hangar01.png", Texture.class);
    Stardust3d.manager.get("data/grid.png", Texture.class).setFilter(TextureFilter.Linear,
            TextureFilter.Linear);
    gridTexture = Stardust3d.manager.get("data/grid.png", Texture.class);
    // hud sprites
    mapTexture = Stardust3d.manager.get("data/iconmap.png", Texture.class);
    thumbControlTexture = Stardust3d.manager.get("data/camcontrol.png", Texture.class);
    shootTexture = Stardust3d.manager.get("data/iconshoot.png", Texture.class);
    missileTexture = Stardust3d.manager.get("data/iconmissile.png", Texture.class);
    dockTexture = Stardust3d.manager.get("data/icondock.png", Texture.class);
    pulloutTexture = Stardust3d.manager.get("data/iconpullout.png", Texture.class);
    stationTexture = Stardust3d.manager.get("data/station01.png", Texture.class);
    repairTexture = Stardust3d.manager.get("data/iconrepair.png", Texture.class);
    speedoTexture = Stardust3d.manager.get("data/speedo.png", Texture.class);
    helpTexture = Stardust3d.manager.get("data/iconhelp.png", Texture.class);
    characterTexture = Stardust3d.manager.get("data/iconcharscreen.png", Texture.class);
    exitTexture = Stardust3d.manager.get("data/iconexit.png", Texture.class);
    logTexture = Stardust3d.manager.get("data/iconlog.png", Texture.class);
    shipiconTexture = Stardust3d.manager.get("data/iconship.png", Texture.class);
    inventoryTexture = Stardust3d.manager.get("data/iconinventory.png", Texture.class);
    missionTexture = Stardust3d.manager.get("data/iconmission.png", Texture.class);
    vendorTexture = Stardust3d.manager.get("data/iconvendor.png", Texture.class);
    buildTexture = Stardust3d.manager.get("data/iconbuild.png", Texture.class);
    cashTexture = Stardust3d.manager.get("data/iconmarket.png", Texture.class);
    optionsTexture = Stardust3d.manager.get("data/iconsetup.png", Texture.class);
    reticuleTexture = Stardust3d.manager.get("data/reticule.png", Texture.class);
    chatTexture = Stardust3d.manager.get("data/iconchat.png", Texture.class);
    gaugetop = new TextureRegion(speedoTexture, 64, 0, 16, 16);
    gaugemiddle = new Sprite(speedoTexture, 64, 16, 16, 32);
    gaugebottom = new TextureRegion(speedoTexture, 64, 48, 16, 16);

}

From source file:com.example.jumpertutorial.JumperTutorial.java

License:Apache License

@Override
public void create() {
    /**//from w  ww. j a  v  a2  s  .com
     * If the viewport's size is not yet known, determine it here.
     */
    if (screenWidth == -1) {
        screenWidth = Gdx.graphics.getWidth();
        screenHeight = Gdx.graphics.getHeight();
    }

    tiledMapHelper = new TiledMapHelper();

    tiledMapHelper = new TiledMapHelper();

    tiledMapHelper.setPackerDirectory("data/packer");

    tiledMapHelper.loadMap("data/world/level1/level.tmx");

    tiledMapHelper.prepareCamera(screenWidth, screenHeight);

    /**
     * Load up the overall texture and chop it in to pieces. In this case,
     * piece.
     */
    overallTexture = new Texture(Gdx.files.internal("data/sprite.png"));
    overallTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

    jumperSprite = new Sprite(overallTexture, 0, 0, 21, 37);

    spriteBatch = new SpriteBatch();

    /**
     * You can set the world's gravity in its constructor. Here, the gravity
     * is negative in the y direction (as in, pulling things down).
     */
    world = new World(new Vector2(0.0f, -10.0f), true);

    BodyDef jumperBodyDef = new BodyDef();
    jumperBodyDef.type = BodyDef.BodyType.DynamicBody;
    jumperBodyDef.position.set(1.0f, 3.0f);

    jumper = world.createBody(jumperBodyDef);

    /**
     * Boxes are defined by their "half width" and "half height", hence the
     * 2 multiplier.
     */
    PolygonShape jumperShape = new PolygonShape();
    jumperShape.setAsBox(jumperSprite.getWidth() / (2 * PIXELS_PER_METER),
            jumperSprite.getHeight() / (2 * PIXELS_PER_METER));

    /**
     * The character should not ever spin around on impact.
     */
    jumper.setFixedRotation(true);

    /**
     * The density and friction of the jumper were found experimentally.
     * Play with the numbers and watch how the character moves faster or
     * slower.
     */
    FixtureDef jumperFixtureDef = new FixtureDef();
    jumperFixtureDef.shape = jumperShape;
    jumperFixtureDef.density = 1.0f;
    jumperFixtureDef.friction = 5.0f;

    jumper.createFixture(jumperFixtureDef);
    jumperShape.dispose();

    tiledMapHelper.loadCollisions("data/collisions.txt", world, PIXELS_PER_METER);

    debugRenderer = new Box2DDebugRenderer();

    lastRender = System.nanoTime();
}

From source file:com.game.libgdx.roguelikeengine.Hero.java

License:Open Source License

public Sprite getsprite() {
    return new Sprite(texture, getxspriteposition(), getyspriteposition(), WrapperEngine.TILE_X_SIZE,
            WrapperEngine.TILE_Y_SIZE);
}

From source file:com.group6.penguinsgame.DemoMap.java

License:Apache License

@Override
public void create() {
    /**/*from w  w  w .  j  a  v a2s. com*/
     * If the viewport's size is not yet known, determine it here.
     */
    if (screenWidth == -1) {
        screenWidth = Gdx.graphics.getWidth();
        screenHeight = Gdx.graphics.getHeight();
    }

    tiledMapHelper = new TiledMapHelper();

    tiledMapHelper = new TiledMapHelper();

    tiledMapHelper.setPackerDirectory("data/packer");

    tiledMapHelper.loadMap("data/world/level1/level.tmx");

    tiledMapHelper.prepareCamera(screenWidth, screenHeight);

    /**
     * Load up the overall texture and chop it in to pieces. In this case,
     * piece.
     */
    overallTexture = new Texture(Gdx.files.internal("data/sprite.png"));
    overallTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

    jumperSprite = new Sprite(overallTexture, 0, 0, 31, 37);

    spriteBatch = new SpriteBatch();

    /**
     * You can set the world's gravity in its constructor. Here, the gravity
     * is negative in the y direction (as in, pulling things down).
     */
    // 0. Create a loader for the file saved from the editor.
    // needs work
    BodyEditorLoader loader = new BodyEditorLoader("data/penFig.json");

    world = new World(new Vector2(0.0f, -10.0f), true);

    // 1. Create a BodyDef, as usual.
    BodyDef jumperBodyDef = new BodyDef();//BodyDef bd = new BodyDef();
    jumperBodyDef.type = BodyDef.BodyType.DynamicBody;//bd.type = BodyType.DynamicBody;
    jumperBodyDef.position.set(5.0f, 5.0f);//bd.position.set(0, 0);

    jumper = world.createBody(jumperBodyDef);

    /**
     * Boxes are defined by their "half width" and "half height", hence the
     * 2 multiplier.
     */
    PolygonShape jumperShape = new PolygonShape();
    jumperShape.setAsBox(jumperSprite.getWidth() / (2 * PIXELS_PER_METER),
            jumperSprite.getHeight() / (2 * PIXELS_PER_METER));

    /**
     * The character should not ever spin around on impact.
     */
    jumper.setFixedRotation(true);

    /**
     * The density and friction of the jumper were found experimentally.
     * Play with the numbers and watch how the character moves faster or
     * slower.
     */

    // 2. Create a FixtureDef, as usual.
    FixtureDef jumperFixtureDef = new FixtureDef();//FixtureDef fd = new FixtureDef();
    jumperFixtureDef.shape = jumperShape;
    jumperFixtureDef.density = 0.1f;//fd.density = 1;
    jumperFixtureDef.friction = 2.0f;//fd.friction = 0.5f;
    //fd.restitution = 0.3f;

    // 3. Create a Body, as usual.
    //jumperModel = world.createBody(jumperBodyDef);
    jumper.createFixture(jumperFixtureDef);
    jumperShape.dispose();

    tiledMapHelper.loadCollisions("data/collisions.txt", world, PIXELS_PER_METER);

    // 4. Create the body fixture automatically by using the loader.
    //needs work
    //loader.attachFixture(jumperModel, "test01", jumperFixtureDef, JUMPER_WIDTH);
    //jumperModelOrigin = loader.getOrigin("test01", JUMPER_WIDTH).cpy();

    debugRenderer = new Box2DDebugRenderer();

    lastRender = System.nanoTime();
}

From source file:com.holotrash.lazerdeath2.Maps.InteractedTile.java

License:Open Source License

public InteractedTile(Coord position, Coord region, String mapTilesFile) {
    this.position = position;
    this.sprite = new Sprite(new Texture(Gdx.files.internal(mapTilesFile)), 128 * region.x(), 128 * region.y(),
            128, 128);//from  w ww .j  a  v  a2 s  .c  o m
}

From source file:com.holotrash.lazerdeath2.Units.Dude.java

License:Open Source License

public Dude(String name, Texture texture, int hp, int pp, int speed, int strength, int dodge, int accuracy,
        int ap, Coord position, GameMaster gm, Sprite glamourShot) {
    this.name = name;
    sprite = new Sprite(texture, 0, 0, 128, 128);
    this.hp = hp;
    this.maxHp = hp;
    this.maxPp = pp;
    this.pp = pp;
    this.speed = speed;
    this.strength = strength;
    this.dodge = dodge;
    this.accuracy = accuracy;
    this.maxAp = ap;
    this.ap = ap;
    this.position = position;
    this.gm = gm;
    this.dice = new Random();
    this.weapon = null;
    this.glamourShot = glamourShot;
    this.updateStatusString();

    gm.mapData.setTileOccupied(position, true);
    this.effects = new ArrayList<ConsumableEffect>();
}

From source file:com.holotrash.lazerdeath2.Units.Enemy.java

License:Open Source License

public Enemy(String name, Texture texture, int hp, int speed, int strength, int dodge, int accuracy, int jitter,
        int guts, Coord position, Weapon weapon, Item drop, Sprite glamourShot, GameMaster gm) {
    this.name = name;
    sprite = new Sprite(texture, 0, 0, 128, 128);
    this.hp = hp;
    this.maxHp = hp;
    this.speed = speed;
    this.strength = strength;
    this.dodge = dodge;
    this.accuracy = accuracy;
    this.jitter = jitter;
    this.guts = guts;
    this.position = position;
    this.hasMoved = false;
    this.hasAttacked = false;
    this.dice = new Random();
    this.weapon = weapon;
    this.drop = drop;
    this.glamourShot = glamourShot;
    this.gm = gm;
    this.ap = 2;/*from   www  . j  a  v  a  2s  .c  om*/

    this.displayStats = new ArrayList<String>();
    displayStats.add("NAME: " + this.name.toUpperCase());
    displayStats.add("HP: " + this.hp);
    displayStats.add("SPEED: " + this.speed);
    displayStats.add("DODGE: " + this.dodge);
    if (this.weapon == null) {
        displayStats.add("WEAPON: UNARMED");
    } else {
        displayStats.add("WEAPON: " + this.weapon.toString().toUpperCase());
    }
    gm.mapData.setTileOccupied(position, true);
}

From source file:com.pio.roguelike.actor.ActorSprite.java

public ActorSprite(ASCIIMap map) {
    if (map == null) {
        return;//from   w  w  w.  jav a  2  s  . co m
    }
    xPosition = map.start_pos_x();
    yPosition = map.start_pos_y();

    Texture texture = new Texture(Gdx.files.internal("ascii/fira_mono_medium_24.png"));
    texture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);

    sprite = new Sprite(texture, 131, 156, 21, 25);
    sprite.set(sprite);

    this.map = map;

    sprite.translate(map.tile_width() * xPosition, map.tile_height() * (yPosition + 1));

    camera = new OrthographicCamera(800, 600);
    camera.position.set(sprite.getX() + sprite.getWidth() / 2f, sprite.getY() + sprite.getHeight() / 2f, 0);
    camera.update();
}

From source file:com.talas777.ZombieLord.LevelObject.java

License:Open Source License

private void calcSprite(Texture texture, int sizex, int sizey) {
    sprite = new Sprite(texture, 0, 0, sizex, sizey);
    sprite.setX(posx - sizex / 2);/*from   w ww  .jav a2 s .  c o m*/
    sprite.setY(posy - sizey / 2);
}