Package com.badlogic.gdx.graphics.g2d

Examples of com.badlogic.gdx.graphics.g2d.TextureRegion


    public static TransientGDXImage load(String fileName) {
        Log.info("Load from file: "+fileName);
            Texture texture = new Texture(Gdx.files.internal(fileName));
            TransientGDXImage newImage = new TransientGDXImage();
           
            newImage.image = new TextureRegion(texture, 0, 0, texture.getWidth(), texture.getHeight());       
            //newImage.image.flip(false, true);
            return newImage;
    }
View Full Code Here


    }
       
   
  public static TextureRegion load (String name, int width, int height) {
    Texture texture = new Texture(Gdx.files.internal(name));
    TextureRegion region = new TextureRegion(texture, 0, 0, width, height);
    //region.flip(false, true);
    return region;
  }    
View Full Code Here

    int xSlices = texture.getWidth() / width;
    int ySlices = texture.getHeight() / height;
    TextureRegion[][] res = new TextureRegion[xSlices][ySlices];
    for (int x = 0; x < xSlices; x++) {
      for (int y = 0; y < ySlices; y++) {
        res[x][y] = new TextureRegion(texture, x * width, y * height, width, height);
        res[x][y].flip(flipX, true);
      }
    }
    return res;
  }
View Full Code Here

      String[] spacingParts = margin.split(" x ");
      int spacingX = Integer.parseInt(spacingParts[0]);
      int spacingY = Integer.parseInt(spacingParts[1]);

      FileHandle image = getRelativeFileHandle(tideFile, imageSource);
      TextureRegion texture = imageResolver.getImage(image.path());

      TiledMapTileSets tilesets = map.getTileSets();
      int firstgid = 1;
      for (TiledMapTileSet tileset : tilesets) {
        firstgid += tileset.size();
      }

      TiledMapTileSet tileset = new TiledMapTileSet();
      tileset.setName(id);
      tileset.getProperties().put("firstgid", firstgid);
      int gid = firstgid;

      int stopWidth = texture.getRegionWidth() - tileSizeX;
      int stopHeight = texture.getRegionHeight() - tileSizeY;

      for (int y = marginY; y <= stopHeight; y += tileSizeY + spacingY) {
        for (int x = marginX; x <= stopWidth; x += tileSizeX + spacingX) {
          TiledMapTile tile = new StaticTiledMapTile(new TextureRegion(texture, x, y, tileSizeX, tileSizeY));
          tile.setId(gid);
          tileset.putTile(gid++, tile);
        }
      }
View Full Code Here

        imageWidth = element.getChildByName("image").getIntAttribute("width", 0);
        imageHeight = element.getChildByName("image").getIntAttribute("height", 0);
        image = getRelativeFileHandle(tmxFile, imageSource);
      }

      TextureRegion texture = imageResolver.getImage(image.path());

      TiledMapTileSet tileset = new TiledMapTileSet();
      MapProperties props = tileset.getProperties();
      tileset.setName(name);
      props.put("firstgid", firstgid);
      props.put("imagesource", imageSource);
      props.put("imagewidth", imageWidth);
      props.put("imageheight", imageHeight);
      props.put("tilewidth", tilewidth);
      props.put("tileheight", tileheight);
      props.put("margin", margin);
      props.put("spacing", spacing);

      int stopWidth = texture.getRegionWidth() - tilewidth;
      int stopHeight = texture.getRegionHeight() - tileheight;

      int id = firstgid;

      for (int y = margin; y <= stopHeight; y += tileheight + spacing) {
        for (int x = margin; x <= stopWidth; x += tilewidth + spacing) {
          TextureRegion tileRegion = new TextureRegion(texture, x, y, tilewidth, tileheight);
          TiledMapTile tile = new StaticTiledMapTile(tileRegion);
          tile.setId(id);
          tile.setOffsetX(offsetX);
          tile.setOffsetY(-offsetY);
          tileset.putTile(id++, tile);
View Full Code Here

    updated = false;
  }

  /** Re-applies the uv coordinates from the material's texture region to the uv components of the vertices array */
  protected void updateUVs () {
    TextureRegion tr = material.textureRegion;
    // left top
    vertices[U1] = tr.getU();
    vertices[V1] = tr.getV();
    // right top
    vertices[U2] = tr.getU2();
    vertices[V2] = tr.getV();
    // left bot
    vertices[U3] = tr.getU();
    vertices[V3] = tr.getV2();
    // right bot
    vertices[U4] = tr.getU2();
    vertices[V4] = tr.getV2();
  }
View Full Code Here

    this.regions = new Array<AspectTextureRegion>( false, regions.length, AspectTextureRegion.class);
    add(regions);
  }
 
  public RegionInfluencer(Texture texture){
    this(new TextureRegion(texture));
  }
View Full Code Here

   * @param texture
   * @param x
   * @param y
   */
  public Character(Texture texture, float x, float y) {
    currentFrame = new TextureRegion(texture);
    position = new Vector2(x, y);
    rect = new Rectangle(x, y, texture.getWidth(), texture.getHeight());
  }
View Full Code Here

        if (tile != null) {
          final boolean flipX = cell.getFlipHorizontally();
          final boolean flipY = cell.getFlipVertically();
          final int rotations = cell.getRotation();

          TextureRegion region = tile.getTextureRegion();

          float x1 = x + tile.getOffsetX() * unitScale;
          float y1 = y + tile.getOffsetY() * unitScale;
          float x2 = x1 + region.getRegionWidth() * unitScale;
          float y2 = y1 + region.getRegionHeight() * unitScale;

          float u1 = region.getU();
          float v1 = region.getV2();
          float u2 = region.getU2();
          float v2 = region.getV();

          vertices[X1] = x1;
          vertices[Y1] = y1;
          vertices[C1] = color;
          vertices[U1] = u1;
          vertices[V1] = v1;

          vertices[X2] = x1;
          vertices[Y2] = y2;
          vertices[C2] = color;
          vertices[U2] = u1;
          vertices[V2] = v2;

          vertices[X3] = x2;
          vertices[Y3] = y2;
          vertices[C3] = color;
          vertices[U3] = u2;
          vertices[V3] = v2;

          vertices[X4] = x2;
          vertices[Y4] = y1;
          vertices[C4] = color;
          vertices[U4] = u2;
          vertices[V4] = v1;

          if (flipX) {
            float temp = vertices[U1];
            vertices[U1] = vertices[U3];
            vertices[U3] = temp;
            temp = vertices[U2];
            vertices[U2] = vertices[U4];
            vertices[U4] = temp;
          }
          if (flipY) {
            float temp = vertices[V1];
            vertices[V1] = vertices[V3];
            vertices[V3] = temp;
            temp = vertices[V2];
            vertices[V2] = vertices[V4];
            vertices[V4] = temp;
          }
          if (rotations != 0) {
            switch (rotations) {
            case Cell.ROTATE_90: {
              float tempV = vertices[V1];
              vertices[V1] = vertices[V2];
              vertices[V2] = vertices[V3];
              vertices[V3] = vertices[V4];
              vertices[V4] = tempV;

              float tempU = vertices[U1];
              vertices[U1] = vertices[U2];
              vertices[U2] = vertices[U3];
              vertices[U3] = vertices[U4];
              vertices[U4] = tempU;
              break;
            }
            case Cell.ROTATE_180: {
              float tempU = vertices[U1];
              vertices[U1] = vertices[U3];
              vertices[U3] = tempU;
              tempU = vertices[U2];
              vertices[U2] = vertices[U4];
              vertices[U4] = tempU;
              float tempV = vertices[V1];
              vertices[V1] = vertices[V3];
              vertices[V3] = tempV;
              tempV = vertices[V2];
              vertices[V2] = vertices[V4];
              vertices[V4] = tempV;
              break;
            }
            case Cell.ROTATE_270: {
              float tempV = vertices[V1];
              vertices[V1] = vertices[V4];
              vertices[V4] = vertices[V3];
              vertices[V3] = vertices[V2];
              vertices[V2] = tempV;

              float tempU = vertices[U1];
              vertices[U1] = vertices[U4];
              vertices[U4] = vertices[U3];
              vertices[U3] = vertices[U2];
              vertices[U2] = tempU;
              break;
            }
            }
          }
          spriteBatch.draw(region.getTexture(), vertices, 0, 20);
        }
      }
    }
  }
View Full Code Here

        if (tile != null) {
          final boolean flipX = cell.getFlipHorizontally();
          final boolean flipY = cell.getFlipVertically();
          final int rotations = cell.getRotation();

          TextureRegion region = tile.getTextureRegion();

          float x1 = x + tile.getOffsetX() * unitScale;
          float y1 = y + tile.getOffsetY() * unitScale;
          float x2 = x1 + region.getRegionWidth() * unitScale;
          float y2 = y1 + region.getRegionHeight() * unitScale;

          float u1 = region.getU();
          float v1 = region.getV2();
          float u2 = region.getU2();
          float v2 = region.getV();

          vertices[X1] = x1;
          vertices[Y1] = y1;
          vertices[C1] = color;
          vertices[U1] = u1;
          vertices[V1] = v1;

          vertices[X2] = x1;
          vertices[Y2] = y2;
          vertices[C2] = color;
          vertices[U2] = u1;
          vertices[V2] = v2;

          vertices[X3] = x2;
          vertices[Y3] = y2;
          vertices[C3] = color;
          vertices[U3] = u2;
          vertices[V3] = v2;

          vertices[X4] = x2;
          vertices[Y4] = y1;
          vertices[C4] = color;
          vertices[U4] = u2;
          vertices[V4] = v1;

          if (flipX) {
            float temp = vertices[U1];
            vertices[U1] = vertices[U3];
            vertices[U3] = temp;
            temp = vertices[U2];
            vertices[U2] = vertices[U4];
            vertices[U4] = temp;
          }
          if (flipY) {
            float temp = vertices[V1];
            vertices[V1] = vertices[V3];
            vertices[V3] = temp;
            temp = vertices[V2];
            vertices[V2] = vertices[V4];
            vertices[V4] = temp;
          }
          if (rotations != 0) {
            switch (rotations) {
            case Cell.ROTATE_90: {
              float tempV = vertices[V1];
              vertices[V1] = vertices[V2];
              vertices[V2] = vertices[V3];
              vertices[V3] = vertices[V4];
              vertices[V4] = tempV;

              float tempU = vertices[U1];
              vertices[U1] = vertices[U2];
              vertices[U2] = vertices[U3];
              vertices[U3] = vertices[U4];
              vertices[U4] = tempU;
              break;
            }
            case Cell.ROTATE_180: {
              float tempU = vertices[U1];
              vertices[U1] = vertices[U3];
              vertices[U3] = tempU;
              tempU = vertices[U2];
              vertices[U2] = vertices[U4];
              vertices[U4] = tempU;
              float tempV = vertices[V1];
              vertices[V1] = vertices[V3];
              vertices[V3] = tempV;
              tempV = vertices[V2];
              vertices[V2] = vertices[V4];
              vertices[V4] = tempV;
              break;
            }
            case Cell.ROTATE_270: {
              float tempV = vertices[V1];
              vertices[V1] = vertices[V4];
              vertices[V4] = vertices[V3];
              vertices[V3] = vertices[V2];
              vertices[V2] = tempV;

              float tempU = vertices[U1];
              vertices[U1] = vertices[U4];
              vertices[U4] = vertices[U3];
              vertices[U3] = vertices[U2];
              vertices[U2] = tempU;
              break;
            }
            }
          }
          spriteBatch.draw(region.getTexture(), vertices, 0, 20);
        }
        x += layerTileWidth;
      }
      y -= layerTileHeight;
    }
View Full Code Here

TOP

Related Classes of com.badlogic.gdx.graphics.g2d.TextureRegion

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.