Package com.badlogic.gdx.files

Examples of com.badlogic.gdx.files.FileHandle


      String source = element.getAttribute("source", null);

      String imageSource = "";
      int imageWidth = 0, imageHeight = 0;

      FileHandle image = null;
      if (source != null) {
        FileHandle tsx = getRelativeFileHandle(tmxFile, source);
        try {
          element = xml.parse(tsx);
          name = element.get("name", null);
          tilewidth = element.getIntAttribute("tilewidth", 0);
          tileheight = element.getIntAttribute("tileheight", 0);
          spacing = element.getIntAttribute("spacing", 0);
          margin = element.getIntAttribute("margin", 0);
          imageSource = element.getChildByName("image").getAttribute("source");
          imageWidth = element.getChildByName("image").getIntAttribute("width", 0);
          imageHeight = element.getChildByName("image").getIntAttribute("height", 0);
        } catch (IOException e) {
          throw new GdxRuntimeException("Error parsing external tileset.");
        }
      } else {
        imageSource = element.getChildByName("image").getAttribute("source");
        imageWidth = element.getChildByName("image").getIntAttribute("width", 0);
        imageHeight = element.getChildByName("image").getIntAttribute("height", 0);
      }

      if (!map.getProperties().containsKey("atlas")) {
        throw new GdxRuntimeException("The map is missing the 'atlas' property");
      }

      // get the TextureAtlas for this tileset
      FileHandle atlasHandle = getRelativeFileHandle(tmxFile, map.getProperties().get("atlas", String.class));
      atlasHandle = resolve(atlasHandle.path());
      TextureAtlas atlas = resolver.getAtlas(atlasHandle.path());
      String regionsName = atlasHandle.nameWithoutExtension();

      if (parameter != null && parameter.forceTextureFilters) {
        for (Texture texture : atlas.getTextures()) {
          trackedTextures.add(texture);
        }
View Full Code Here


    return cell;
  }

  public static FileHandle getRelativeFileHandle (FileHandle file, String path) {
    StringTokenizer tokenizer = new StringTokenizer(path, "\\/");
    FileHandle result = file.parent();
    while (tokenizer.hasMoreElements()) {
      String token = tokenizer.nextToken();
      if (token.equals(".."))
        result = result.parent();
      else {
        result = result.child(token);
      }
    }
    return result;
  }
View Full Code Here

   * @param parameters specifies whether to use y-up, generate mip maps etc.
   * @return the TiledMap */
  public TiledMap load (String fileName, TmxMapLoader.Parameters parameters) {
    try {
      this.yUp = parameters.yUp;
      FileHandle tmxFile = resolve(fileName);
      root = xml.parse(tmxFile);
      ObjectMap<String, Texture> textures = new ObjectMap<String, Texture>();
      for (FileHandle textureFile : loadTilesets(root, tmxFile)) {
        Texture texture = new Texture(textureFile, parameters.generateMipMaps);
        texture.setFilter(parameters.textureMinFilter, parameters.textureMagFilter);
View Full Code Here

   * @throws IOException */
  protected Array<FileHandle> loadTilesets (Element root, FileHandle tmxFile) throws IOException {
    Array<FileHandle> images = new Array<FileHandle>();
    for (Element tileset : root.getChildrenByName("tileset")) {
      String source = tileset.getAttribute("source", null);
      FileHandle image = null;
      if (source != null) {
        FileHandle tsx = getRelativeFileHandle(tmxFile, source);
        tileset = xml.parse(tsx);
        String imageSource = tileset.getChildByName("image").getAttribute("source");
        image = getRelativeFileHandle(tsx, imageSource);
      } else {
        String imageSource = tileset.getChildByName("image").getAttribute("source");
View Full Code Here

      String source = element.getAttribute("source", null);

      String imageSource = "";
      int imageWidth = 0, imageHeight = 0;

      FileHandle image = null;
      if (source != null) {
        FileHandle tsx = getRelativeFileHandle(tmxFile, source);
        try {
          element = xml.parse(tsx);
          name = element.get("name", null);
          tilewidth = element.getIntAttribute("tilewidth", 0);
          tileheight = element.getIntAttribute("tileheight", 0);
View Full Code Here

    return cell;
  }

  protected static FileHandle getRelativeFileHandle (FileHandle file, String path) {
    StringTokenizer tokenizer = new StringTokenizer(path, "\\/");
    FileHandle result = file.parent();
    while (tokenizer.hasMoreElements()) {
      String token = tokenizer.nextToken();
      if (token.equals(".."))
        result = result.parent();
      else {
        result = result.child(token);
      }
    }
    return result;
  }
View Full Code Here

      File outputFile;
      while (true) {
        outputFile = new File(packDir, imageName + (fileIndex++ == 0 ? "" : fileIndex) + "." + settings.outputFormat);
        if (!outputFile.exists()) break;
      }
      new FileHandle(outputFile).parent().mkdirs();
      page.imageName = outputFile.getName();

      BufferedImage canvas = new BufferedImage(width, height, getBufferedImageType(settings.format));
      Graphics2D g = (Graphics2D)canvas.getGraphics();
View Full Code Here

    private void loadImage (ParticleEmitter emitter) {
      final String imagePath = emitter.getImagePath();
      String imageName = new File(imagePath.replace('\\', '/')).getName();
      try {
        FileHandle file;
        if (imagePath.equals(ParticleEditor.DEFAULT_PARTICLE))
          file = Gdx.files.classpath(imagePath);
        else
          file = Gdx.files.absolute(imagePath);
        emitter.setSprite(new Sprite(new Texture(file)));
View Full Code Here

  }

  private void writePackFile (File packFile, Array<Page> pages) throws IOException {
    if (packFile.exists()) {
      // Make sure there aren't duplicate names.
      TextureAtlasData textureAtlasData = new TextureAtlasData(new FileHandle(packFile), new FileHandle(packFile), false);
      for (Page page : pages) {
        for (Rect rect : page.outputRects) {
          String rectName = Rect.getAtlasName(rect.name, settings.flattenPaths);
          for (Region region : textureAtlasData.getRegions()) {
            if (region.name.equals(rectName)) {
View Full Code Here

    public String toString () {
      return name + "[" + x + "," + y + " " + width + "x" + height + "]";
    }

    static public String getAtlasName (String name, boolean flattenPaths) {
      return flattenPaths ? new FileHandle(name).name() : name;
    }
View Full Code Here

TOP

Related Classes of com.badlogic.gdx.files.FileHandle

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.