Package com.badlogic.gdx.files

Examples of com.badlogic.gdx.files.FileHandle


  }

  @Override
  public FileHandle resolve (String fileName) {
    Resolution bestDesc = choose(descriptors);
    FileHandle originalHandle = new GwtFileHandle(fileName);
    FileHandle handle = baseResolver.resolve(resolve(originalHandle, bestDesc.suffix));
    if (!handle.exists()) handle = baseResolver.resolve(fileName);
    return handle;
  }
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.convertObjectToTileSpace = parameters.convertObjectToTileSpace;
      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

      int offsetY = 0;

      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

      if (properties != null) {
        for (Element property : properties.getChildrenByName("property")) {
          String name = property.getAttribute("name");
          String value = property.getAttribute("value");
          if (name.startsWith("atlas")) {
            FileHandle atlasHandle = getRelativeFileHandle(tmxFile, value);
            dependencies.add(new AssetDescriptor(atlasHandle, TextureAtlas.class));
          }
        }
      }
    } catch (IOException e) {
View Full Code Here

        convertObjectToTileSpace = parameter.convertObjectToTileSpace;
      } else {
        convertObjectToTileSpace = false;
      }

      FileHandle tmxFile = resolve(fileName);
      root = xml.parse(tmxFile);
      ObjectMap<String, TextureAtlas> atlases = new ObjectMap<String, TextureAtlas>();
      FileHandle atlasFile = loadAtlas(root, tmxFile);
      if (atlasFile == null) {
        throw new GdxRuntimeException("Couldn't load atlas");
      }

      TextureAtlas atlas = new TextureAtlas(atlasFile);
      atlases.put(atlasFile.path(), atlas);

      AtlasResolver.DirectAtlasResolver atlasResolver = new AtlasResolver.DirectAtlasResolver(atlases);
      TiledMap map = loadMap(root, tmxFile, atlasResolver, parameter);
      map.setOwnedResources(atlases.values().toArray());
      setTextureFilters(parameter.textureMinFilter, parameter.textureMagFilter);
View Full Code Here

          return getRelativeFileHandle(tmxFile, value);
        }
      }
    } else {
      FileHandle atlasFile = tmxFile.sibling(tmxFile.nameWithoutExtension() + ".atlas");
      return atlasFile.exists() ? atlasFile : null;
    }

    return null;
  }
View Full Code Here

      int offsetY = 0;

      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);
          Element offset = element.getChildByName("tileoffset");
          if (offset != null) {
            offsetX = offset.getIntAttribute("x", 0);
            offsetY = offset.getIntAttribute("y", 0);
          }
          Element imageElement = element.getChildByName("image");
          imageSource = imageElement.getAttribute("source");
          imageWidth = imageElement.getIntAttribute("width", 0);
          imageHeight = imageElement.getIntAttribute("height", 0);
        } catch (IOException e) {
          throw new GdxRuntimeException("Error parsing external tileset.");
        }
      } else {
        Element offset = element.getChildByName("tileoffset");
        if (offset != null) {
          offsetX = offset.getIntAttribute("x", 0);
          offsetY = offset.getIntAttribute("y", 0);
        }
        Element imageElement = element.getChildByName("image");
        if (imageElement != null) {
          imageSource = imageElement.getAttribute("source");
          imageWidth = imageElement.getIntAttribute("width", 0);
          imageHeight = imageElement.getIntAttribute("height", 0);
        }
      }

      String atlasFilePath = map.getProperties().get("atlas", String.class);
      if (atlasFilePath == null) {
        FileHandle atlasFile = tmxFile.sibling(tmxFile.nameWithoutExtension() + ".atlas");
        if (atlasFile.exists()) atlasFilePath = atlasFile.name();
      }
      if (atlasFilePath == null) {
        throw new GdxRuntimeException("The map is missing the 'atlas' property");
      }

      // get the TextureAtlas for this tileset
      FileHandle atlasHandle = getRelativeFileHandle(tmxFile, atlasFilePath);
      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

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.