Package com.badlogic.gdx.utils

Examples of com.badlogic.gdx.utils.GdxRuntimeException


      BufferedReader reader = new BufferedReader(new InputStreamReader(fontFile.read()), 512);
      try {
        reader.readLine(); // info

        String line = reader.readLine();
        if (line == null) throw new GdxRuntimeException("Invalid font file: " + fontFile);
        String[] common = line.split(" ", 4);
        if (common.length < 4) throw new GdxRuntimeException("Invalid font file: " + fontFile);

        if (!common[1].startsWith("lineHeight=")) throw new GdxRuntimeException("Invalid font file: " + fontFile);
        lineHeight = Integer.parseInt(common[1].substring(11));

        if (!common[2].startsWith("base=")) throw new GdxRuntimeException("Invalid font file: " + fontFile);
        int baseLine = Integer.parseInt(common[2].substring(5));

        line = reader.readLine();
        if (line == null) throw new GdxRuntimeException("Invalid font file: " + fontFile);
        String[] pageLine = line.split(" ", 4);
        if (!pageLine[2].startsWith("file=")) throw new GdxRuntimeException("Invalid font file: " + fontFile);
        String imgFilename = null;
        if (pageLine[2].endsWith("\"")) {
          imgFilename = pageLine[2].substring(6, pageLine[2].length() - 1);
        } else {
          imgFilename = pageLine[2].substring(5, pageLine[2].length());
        }
        imagePath = fontFile.parent().child(imgFilename).path().replaceAll("\\\\", "/");
        descent = 0;

        while (true) {
          line = reader.readLine();
          if (line == null) break;
          if (line.startsWith("kernings ")) break;
          if (!line.startsWith("char ")) continue;

          Glyph glyph = new Glyph();

          StringTokenizer tokens = new StringTokenizer(line, " =");
          tokens.nextToken();
          tokens.nextToken();
          int ch = Integer.parseInt(tokens.nextToken());
          if (ch <= Character.MAX_VALUE)
            setGlyph(ch, glyph);
          else
            continue;
          tokens.nextToken();
          glyph.srcX = Integer.parseInt(tokens.nextToken());
          tokens.nextToken();
          glyph.srcY = Integer.parseInt(tokens.nextToken());
          tokens.nextToken();
          glyph.width = Integer.parseInt(tokens.nextToken());
          tokens.nextToken();
          glyph.height = Integer.parseInt(tokens.nextToken());
          tokens.nextToken();
          glyph.xoffset = Integer.parseInt(tokens.nextToken());
          tokens.nextToken();
          if (flip)
            glyph.yoffset = Integer.parseInt(tokens.nextToken());
          else
            glyph.yoffset = -(glyph.height + Integer.parseInt(tokens.nextToken()));
          tokens.nextToken();
          glyph.xadvance = Integer.parseInt(tokens.nextToken());
          descent = Math.min(baseLine + glyph.yoffset, descent);
        }

        while (true) {
          line = reader.readLine();
          if (line == null) break;
          if (!line.startsWith("kerning ")) break;

          StringTokenizer tokens = new StringTokenizer(line, " =");
          tokens.nextToken();
          tokens.nextToken();
          int first = Integer.parseInt(tokens.nextToken());
          tokens.nextToken();
          int second = Integer.parseInt(tokens.nextToken());
          if (first < 0 || first > Character.MAX_VALUE || second < 0 || second > Character.MAX_VALUE) continue;
          Glyph glyph = getGlyph((char)first);
          tokens.nextToken();
          int amount = Integer.parseInt(tokens.nextToken());
          glyph.setKerning(second, amount);
        }

        Glyph spaceGlyph = getGlyph(' ');
        if (spaceGlyph == null) {
          spaceGlyph = new Glyph();
          Glyph xadvanceGlyph = getGlyph('l');
          if (xadvanceGlyph == null) xadvanceGlyph = getFirstGlyph();
          spaceGlyph.xadvance = xadvanceGlyph.xadvance;
          setGlyph(' ', spaceGlyph);
        }
        spaceWidth = spaceGlyph != null ? spaceGlyph.xadvance + spaceGlyph.width : 1;

        Glyph xGlyph = null;
        for (int i = 0; i < xChars.length; i++) {
          xGlyph = getGlyph(xChars[i]);
          if (xGlyph != null) break;
        }
        if (xGlyph == null) xGlyph = getFirstGlyph();
        xHeight = xGlyph.height;

        Glyph capGlyph = null;
        for (int i = 0; i < capChars.length; i++) {
          capGlyph = getGlyph(capChars[i]);
          if (capGlyph != null) break;
        }
        if (xGlyph == null) xGlyph = getFirstGlyph();
        capHeight = capGlyph.height;

        ascent = baseLine - capHeight;
        down = -lineHeight;
        if (flip) {
          ascent = -ascent;
          down = -down;
        }
      } catch (Exception ex) {
        throw new GdxRuntimeException("Error loading font file: " + fontFile, ex);
      } finally {
        try {
          reader.close();
        } catch (IOException ignored) {
        }
View Full Code Here


        for (Glyph glyph : page) {
          if (glyph == null) continue;
          return glyph;
        }
      }
      throw new GdxRuntimeException("No glyphs found!");
    }
View Full Code Here

            doc = docBuilder.parse(tmxFileHandle.read());

            Node map = doc.getFirstChild();
            while (map.getNodeType() != Node.ELEMENT_NODE || map.getNodeName() != "map") {
                if ((map = map.getNextSibling()) == null) {
                    throw new GdxRuntimeException("Couldn't find map node!");
                }
            }

            setProperty(doc, map, "blended tiles", toCSV(blendedTiles));
View Full Code Here

      DirectImageResolver imageResolver = new DirectImageResolver(textures);
      TiledMap map = loadTilemap(root, tmxFile, imageResolver);
      map.setOwnedResources(textures.values().toArray());
      return map;
    } catch (IOException e) {
      throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e);
    }
  }
View Full Code Here

      convertObjectToTileSpace = false;
    }
    try {
      map = loadTilemap(root, tmxFile, new AssetManagerImageResolver(manager));
    } catch (Exception e) {
      throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e);
    }
  }
View Full Code Here

      for (FileHandle image : loadTilesets(root, tmxFile)) {
        dependencies.add(new AssetDescriptor(image, Texture.class, texParams));
      }
      return dependencies;
    } catch (IOException e) {
      throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e);
    }
  }
View Full Code Here

          imageSource = element.getChildByName("image").getAttribute("source");
          imageWidth = element.getChildByName("image").getIntAttribute("width", 0);
          imageHeight = element.getChildByName("image").getIntAttribute("height", 0);
          image = getRelativeFileHandle(tsx, imageSource);
        } catch (IOException e) {
          throw new GdxRuntimeException("Error parsing external tileset.");
        }
      } else {
        Element offset = element.getChildByName("tileoffset");
        if (offset != null) {
          offsetX = offset.getIntAttribute("x", 0);
View Full Code Here

   * The call to this method must be paired with a call to {@link #end()}.
   *
   * In case OpenGL ES 1.x is used, the projection and modelview matrix will be modified.
   * @param type the {@link ShapeType}. */
  public void begin (ShapeType type) {
    if (currType != null) throw new GdxRuntimeException("Call end() before beginning a new shape batch");
    currType = type;
    if (matrixDirty) {
      combined.set(projView);
      Matrix4.mul(combined.val, transform.val);
      matrixDirty = false;
View Full Code Here

  /** Draws a point. The {@link ShapeType} passed to begin has to be {@link ShapeType#Point}.
   * @param x
   * @param y
   * @param z */
  public void point (float x, float y, float z) {
    if (currType != ShapeType.Point) throw new GdxRuntimeException("Must call begin(ShapeType.Point)");
    checkDirty();
    checkFlush(1);
    renderer.color(color);
    renderer.vertex(x, y, z);
  }
View Full Code Here

  /** Draws a line. The {@link ShapeType} passed to begin has to be {@link ShapeType#Line}. The line is drawn with 2 colors
   * interpolated between start & end point.
   * @param c1 Color at start of the line
   * @param c2 Color at end of the line */
  public void line (float x, float y, float z, float x2, float y2, float z2, Color c1, Color c2) {
    if (currType != ShapeType.Line) throw new GdxRuntimeException("Must call begin(ShapeType.Line)");
    checkDirty();
    checkFlush(2);
    renderer.color(c1.r, c1.g, c1.b, c1.a);
    renderer.vertex(x, y, z);
    renderer.color(c2.r, c2.g, c2.b, c2.a);
View Full Code Here

TOP

Related Classes of com.badlogic.gdx.utils.GdxRuntimeException

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.