Package com.badlogic.gdx.utils

Examples of com.badlogic.gdx.utils.GdxRuntimeException


  }

  public void circle (float x, float y, float radius, int segments) {
    if (segments <= 0) throw new IllegalArgumentException("segments must be > 0.");
    if (currType != ShapeType.Filled && currType != ShapeType.Line)
      throw new GdxRuntimeException("Must call begin(ShapeType.Filled) or begin(ShapeType.Line)");
    checkDirty();

    float angle = 2 * MathUtils.PI / segments;
    float cos = MathUtils.cos(angle);
    float sin = MathUtils.sin(angle);
View Full Code Here


  }

  public void ellipse (float x, float y, float width, float height, int segments) {
    if (segments <= 0) throw new IllegalArgumentException("segments must be > 0.");
    if (currType != ShapeType.Filled && currType != ShapeType.Line)
      throw new GdxRuntimeException("Must call begin(ShapeType.Filled) or begin(ShapeType.Line)");
    checkDirty();
    checkFlush(segments * 3);

    float angle = 2 * MathUtils.PI / segments;

View Full Code Here

  }

  public void cone (float x, float y, float z, float radius, float height, int segments) {
    if (segments <= 0) throw new IllegalArgumentException("segments must be > 0.");
    if (currType != ShapeType.Filled && currType != ShapeType.Line)
      throw new GdxRuntimeException("Must call begin(ShapeType.Filled) or begin(ShapeType.Line)");
    checkDirty();
    checkFlush(segments * 4 + 2);
    float angle = 2 * MathUtils.PI / segments;
    float cos = MathUtils.cos(angle);
    float sin = MathUtils.sin(angle);
View Full Code Here

  /** Draws a polygon in the x/y plane. The vertices must contain at least 3 points (6 floats x,y). The {@link ShapeType} passed
   * to begin has to be {@link ShapeType#Line}.
   * @param vertices */
  public void polygon (float[] vertices, int offset, int count) {
    if (currType != ShapeType.Line) throw new GdxRuntimeException("Must call begin(ShapeType.Line)");
    if (count < 6) throw new IllegalArgumentException("Polygons must contain at least 3 points.");
    if (count % 2 != 0) throw new IllegalArgumentException("Polygons must have an even number of vertices.");

    checkDirty();
    checkFlush(count);
View Full Code Here

  /** Draws a polyline in the x/y plane. The vertices must contain at least 2 points (4 floats x,y). The {@link ShapeType} passed
   * to begin has to be {@link ShapeType#Line}.
   * @param vertices */
  public void polyline (float[] vertices, int offset, int count) {
    if (currType != ShapeType.Line) throw new GdxRuntimeException("Must call begin(ShapeType.Line)");
    if (count < 4) throw new IllegalArgumentException("Polylines must contain at least 2 points.");
    if (count % 2 != 0) throw new IllegalArgumentException("Polylines must have an even number of vertices.");

    checkDirty();
    checkFlush(count);
View Full Code Here

        emitters.add(emitter);
        if (reader.readLine() == null) break;
        if (reader.readLine() == null) break;
      }
    } catch (IOException ex) {
      throw new GdxRuntimeException("Error loading effect: " + effectFile, ex);
    } finally {
      StreamUtils.closeQuietly(reader);
    }
  }
View Full Code Here

   * succeed.
   * @param font the {@link FileHandle} to the TrueType font file */
  public FreeTypeFontGenerator (FileHandle font) {
    filePath = font.pathWithoutExtension();
    library = FreeType.initFreeType();
    if (library == null) throw new GdxRuntimeException("Couldn't initialize FreeType");
    face = FreeType.newFace(library, font, 0);
    if (face == null) throw new GdxRuntimeException("Couldn't create face for font '" + font + "'");
    if (checkForBitmapFont()) {
      return;
    }
    if (!FreeType.setPixelSizes(face, 0, 15)) throw new GdxRuntimeException("Couldn't set size for font '" + font + "'");
  }
View Full Code Here

  }

  /** Uses ascender and descender of font to calculate real height that makes all glyphs to fit in given pixel size. Source:
   * http://nothings.org/stb/stb_truetype.h / stbtt_ScaleForPixelHeight */
  public int scaleForPixelHeight (int size) {
    if (!bitmapped && !FreeType.setPixelSizes(face, 0, size)) throw new GdxRuntimeException("Couldn't set size for font");
    SizeMetrics fontMetrics = face.getSize().getMetrics();
    int ascent = FreeType.toInt(fontMetrics.getAscender());
    int descent = FreeType.toInt(fontMetrics.getDescender());
    return size * size / (ascent - descent);
  }
View Full Code Here

  }

  /** Returns null if glyph was not found. If there is nothing to render, for example with various space characters, then bitmap
   * is null. */
  public GlyphAndBitmap generateGlyphAndBitmap (int c, int size, boolean flip) {
    if (!bitmapped && !FreeType.setPixelSizes(face, 0, size)) throw new GdxRuntimeException("Couldn't set size for font");

    SizeMetrics fontMetrics = face.getSize().getMetrics();
    int baseline = FreeType.toInt(fontMetrics.getAscender());

    // Check if character exists in this font.
    // 0 means 'undefined character code'
    if (FreeType.getCharIndex(face, c) == 0) {
      return null;
    }

    // Try to load character
    if (!FreeType.loadChar(face, c, FreeType.FT_LOAD_DEFAULT)) {
      throw new GdxRuntimeException("Unable to load character!");
    }

    GlyphSlot slot = face.getGlyph();

    // Try to render to bitmap
View Full Code Here

  public FreeTypeBitmapFontData generateData (FreeTypeFontParameter parameter) {
    parameter = parameter == null ? new FreeTypeFontParameter() : parameter;

    FreeTypeBitmapFontData data = new FreeTypeBitmapFontData();
    if (!bitmapped && !FreeType.setPixelSizes(face, 0, parameter.size))
      throw new GdxRuntimeException("Couldn't set size for font");

    // set general font data
    SizeMetrics fontMetrics = face.getSize().getMetrics();
    data.flipped = parameter.flip;
    data.ascent = FreeType.toInt(fontMetrics.getAscender());
    data.descent = FreeType.toInt(fontMetrics.getDescender());
    data.lineHeight = FreeType.toInt(fontMetrics.getHeight());
    float baseLine = data.ascent;

    // if bitmapped
    if (bitmapped && (data.lineHeight == 0)) {
      for (int c = 32; c < (32 + face.getNumGlyphs()); c++) {
        if (FreeType.loadChar(face, c, FreeType.FT_LOAD_DEFAULT)) {
          int lh = FreeType.toInt(face.getGlyph().getMetrics().getHeight());
          data.lineHeight = (lh > data.lineHeight) ? lh : data.lineHeight;
        }
      }
    }

    // determine space width and set glyph
    if (FreeType.loadChar(face, ' ', FreeType.FT_LOAD_DEFAULT)) {
      data.spaceWidth = FreeType.toInt(face.getGlyph().getMetrics().getHoriAdvance());
    } else {
      data.spaceWidth = face.getMaxAdvanceWidth(); // FIXME possibly very wrong :)
    }
    Glyph spaceGlyph = new Glyph();
    spaceGlyph.xadvance = (int)data.spaceWidth;
    spaceGlyph.id = (int)' ';
    data.setGlyph(' ', spaceGlyph);

    // determine x-height
    for (char xChar : BitmapFont.xChars) {
      if (!FreeType.loadChar(face, xChar, FreeType.FT_LOAD_DEFAULT)) continue;
      data.xHeight = FreeType.toInt(face.getGlyph().getMetrics().getHeight());
      break;
    }
    if (data.xHeight == 0) throw new GdxRuntimeException("No x-height character found in font");
    for (char capChar : BitmapFont.capChars) {
      if (!FreeType.loadChar(face, capChar, FreeType.FT_LOAD_DEFAULT)) continue;
      data.capHeight = FreeType.toInt(face.getGlyph().getMetrics().getHeight());
      break;
    }

    // determine cap height
    if (!bitmapped && data.capHeight == 1) throw new GdxRuntimeException("No cap character found in font");
    data.ascent = data.ascent - data.capHeight;
    data.down = -data.lineHeight;
    if (parameter.flip) {
      data.ascent = -data.ascent;
      data.down = -data.down;
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.