libgdx API

com.badlogic.gdx.graphics.g2d
Class BitmapFontCache

java.lang.Object
  extended by com.badlogic.gdx.graphics.g2d.BitmapFontCache
All Implemented Interfaces:
Disposable

public class BitmapFontCache
extends java.lang.Object
implements Disposable

Caches glyph geometry for a BitmapFont, providing a fast way to render static text. This saves needing to compute the location of each glyph each frame.

Author:
Nathan Sweet, Matthias Mann

Constructor Summary
BitmapFontCache(BitmapFont font)
           
BitmapFontCache(BitmapFont font, boolean integer)
          Creates a new BitmapFontCache
 
Method Summary
 void dispose()
          Disposes the underlying BitmapFont of this cache.
 void draw(SpriteBatch spriteBatch)
           
 void draw(SpriteBatch spriteBatch, float alphaModulation)
           
 BitmapFont.TextBounds getBounds()
          Returns the size of the cached string.
 Color getColor()
           
 BitmapFont getFont()
           
 float getX()
          Returns the x position of the cached string, relative to the position when the string was cached.
 float getY()
          Returns the y position of the cached string, relative to the position when the string was cached.
 void setColor(Color tint)
           
 void setColor(float color)
           
 void setColor(float r, float g, float b, float a)
           
 BitmapFont.TextBounds setMultiLineText(java.lang.CharSequence str, float x, float y)
          Caches a string, which may contain newlines (\n), with the specified position.
 BitmapFont.TextBounds setMultiLineText(java.lang.CharSequence str, float x, float y, float alignmentWidth, BitmapFont.HAlignment alignment)
          Caches a string, which may contain newlines (\n), with the specified position and alignment.
 void setPosition(float x, float y)
          Sets the position of the text, relative to the position when the cached text was created.
 BitmapFont.TextBounds setText(java.lang.CharSequence str, float x, float y)
          Caches a string with the specified position.
 BitmapFont.TextBounds setText(java.lang.CharSequence str, float x, float y, int start, int end)
          Caches a substring with the specified position.
 void setUseIntegerPositions(boolean use)
          Specifies whether to use integer positions or not.
 BitmapFont.TextBounds setWrappedText(java.lang.CharSequence str, float x, float y, float wrapWidth)
          Caches a string, which may contain newlines (\n), with the specified position.
 BitmapFont.TextBounds setWrappedText(java.lang.CharSequence str, float x, float y, float wrapWidth, BitmapFont.HAlignment alignment)
          Caches a string, which may contain newlines (\n), with the specified position.
 void translate(float xAmount, float yAmount)
          Sets the position of the text, relative to its current position.
 boolean usesIntegerPositions()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitmapFontCache

public BitmapFontCache(BitmapFont font)

BitmapFontCache

public BitmapFontCache(BitmapFont font,
                       boolean integer)
Creates a new BitmapFontCache

Parameters:
font - the font to use
integer - whether to use integer positions and sizes.
Method Detail

setPosition

public void setPosition(float x,
                        float y)
Sets the position of the text, relative to the position when the cached text was created.

Parameters:
x - The x coordinate
y - The y coodinate

translate

public void translate(float xAmount,
                      float yAmount)
Sets the position of the text, relative to its current position.

Parameters:
xAmount - The amount in x to move the text
yAmount - The amount in y to move the text

setColor

public void setColor(float color)

setColor

public void setColor(Color tint)

setColor

public void setColor(float r,
                     float g,
                     float b,
                     float a)

draw

public void draw(SpriteBatch spriteBatch)

draw

public void draw(SpriteBatch spriteBatch,
                 float alphaModulation)

getColor

public Color getColor()

setText

public BitmapFont.TextBounds setText(java.lang.CharSequence str,
                                     float x,
                                     float y)
Caches a string with the specified position.

Parameters:
x - The x position for the left most character.
y - The y position for the top of most capital letters in the font (the cap height).
Returns:
The bounds of the cached string (the height is the distance from y to the baseline).

setText

public BitmapFont.TextBounds setText(java.lang.CharSequence str,
                                     float x,
                                     float y,
                                     int start,
                                     int end)
Caches a substring with the specified position.

Parameters:
x - The x position for the left most character.
y - The y position for the top of most capital letters in the font (the cap height).
start - The first character of the string to draw.
end - The last character of the string to draw (exclusive).
Returns:
The bounds of the cached string (the height is the distance from y to the baseline).

setMultiLineText

public BitmapFont.TextBounds setMultiLineText(java.lang.CharSequence str,
                                              float x,
                                              float y)
Caches a string, which may contain newlines (\n), with the specified position.

Parameters:
x - The x position for the left most character.
y - The y position for the top of most capital letters in the font (the cap height).
Returns:
The bounds of the cached string (the height is the distance from y to the baseline of the last line).

setMultiLineText

public BitmapFont.TextBounds setMultiLineText(java.lang.CharSequence str,
                                              float x,
                                              float y,
                                              float alignmentWidth,
                                              BitmapFont.HAlignment alignment)
Caches a string, which may contain newlines (\n), with the specified position and alignment. Each line is aligned horizontally within a rectangle of the specified width.

Parameters:
x - The x position for the left most character.
y - The y position for the top of most capital letters in the font (the cap height).
Returns:
The bounds of the cached string (the height is the distance from y to the baseline of the last line).

setWrappedText

public BitmapFont.TextBounds setWrappedText(java.lang.CharSequence str,
                                            float x,
                                            float y,
                                            float wrapWidth)
Caches a string, which may contain newlines (\n), with the specified position. Each line is automatically wrapped to keep it within a rectangle of the specified width.

Parameters:
x - The x position for the left most character.
y - The y position for the top of most capital letters in the font (the cap height).
Returns:
The bounds of the cached string (the height is the distance from y to the baseline of the last line).

setWrappedText

public BitmapFont.TextBounds setWrappedText(java.lang.CharSequence str,
                                            float x,
                                            float y,
                                            float wrapWidth,
                                            BitmapFont.HAlignment alignment)
Caches a string, which may contain newlines (\n), with the specified position. Each line is automatically wrapped to keep it within a rectangle of the specified width, and aligned horizontally within that rectangle.

Parameters:
x - The x position for the left most character.
y - The y position for the top of most capital letters in the font (the cap height).
Returns:
The bounds of the cached string (the height is the distance from y to the baseline of the last line).

getBounds

public BitmapFont.TextBounds getBounds()
Returns the size of the cached string. The height is the distance from the top of most capital letters in the font (the cap height) to the baseline of the last line of text.


getX

public float getX()
Returns the x position of the cached string, relative to the position when the string was cached.


getY

public float getY()
Returns the y position of the cached string, relative to the position when the string was cached.


getFont

public BitmapFont getFont()

dispose

public void dispose()
Disposes the underlying BitmapFont of this cache.

Specified by:
dispose in interface Disposable

setUseIntegerPositions

public void setUseIntegerPositions(boolean use)
Specifies whether to use integer positions or not. Default is to use them so filtering doesn't kick in as badly.

Parameters:
use -

usesIntegerPositions

public boolean usesIntegerPositions()
Returns:
whether this font uses integer positions for drawing.

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)