com.badlogic.gdx.graphics.g2d
Class BitmapFontCache

java.lang.Object
  extended by com.badlogic.gdx.graphics.g2d.BitmapFontCache

public class BitmapFontCache
extends Object

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
 BitmapFont.TextBounds addMultiLineText(CharSequence str, float x, float y)
          Adds glyphs for the specified text, which may contain newlines (\n).
 BitmapFont.TextBounds addMultiLineText(CharSequence str, float x, float y, float alignmentWidth, BitmapFont.HAlignment alignment)
          Adds glyphs for the specified text, which may contain newlines (\n).
 BitmapFont.TextBounds addText(CharSequence str, float x, float y)
          Adds glyphs for the specified text.
 BitmapFont.TextBounds addText(CharSequence str, float x, float y, int start, int end)
          Adds glyphs for the the specified text.
 BitmapFont.TextBounds addWrappedText(CharSequence str, float x, float y, float wrapWidth)
          Adds glyphs for the specified text, which may contain newlines (\n) and is automatically wrapped within the specified width.
 BitmapFont.TextBounds addWrappedText(CharSequence str, float x, float y, float wrapWidth, BitmapFont.HAlignment alignment)
          Adds glyphs for the specified text, which may contain newlines (\n) and is automatically wrapped within the specified width.
 void clear()
          Removes all glyphs in the cache.
 void draw(SpriteBatch spriteBatch)
           
 void draw(SpriteBatch spriteBatch, float alphaModulation)
           
 void draw(SpriteBatch spriteBatch, int start, int end)
           
 BitmapFont.TextBounds getBounds()
          Returns the size of the cached string.
 Color getColor()
           
 BitmapFont getFont()
           
 float[] getVertices()
           
 float[] getVertices(int page)
           
 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(Color tint, int start, int end)
          Sets the color of the specified characters.
 void setColor(float color)
           
 void setColor(float r, float g, float b, float a)
           
 BitmapFont.TextBounds setMultiLineText(CharSequence str, float x, float y)
          Clears any cached glyphs and adds glyphs for the specified text, which may contain newlines (\n).
 BitmapFont.TextBounds setMultiLineText(CharSequence str, float x, float y, float alignmentWidth, BitmapFont.HAlignment alignment)
          Clears any cached glyphs and adds glyphs for the specified text, which may contain newlines (\n).
 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(CharSequence str, float x, float y)
          Clears any cached glyphs and adds glyphs for the specified text.
 BitmapFont.TextBounds setText(CharSequence str, float x, float y, int start, int end)
          Clears any cached glyphs and adds glyphs for the specified text.
 void setUseIntegerPositions(boolean use)
          Specifies whether to use integer positions or not.
 BitmapFont.TextBounds setWrappedText(CharSequence str, float x, float y, float wrapWidth)
          Clears any cached glyphs and adds glyphs for the specified text, which may contain newlines (\n) and is automatically wrapped within the specified width.
 BitmapFont.TextBounds setWrappedText(CharSequence str, float x, float y, float wrapWidth, BitmapFont.HAlignment alignment)
          Clears any cached glyphs and adds glyphs for the specified text, which may contain newlines (\n) and is automatically wrapped within the specified width.
 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
equals, 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)

setColor

public void setColor(Color tint,
                     int start,
                     int end)
Sets the color of the specified characters. This may only be called after setText(CharSequence, float, float) and is reset every time setText is called.


draw

public void draw(SpriteBatch spriteBatch)

draw

public void draw(SpriteBatch spriteBatch,
                 int start,
                 int end)

draw

public void draw(SpriteBatch spriteBatch,
                 float alphaModulation)

getColor

public Color getColor()

clear

public void clear()
Removes all glyphs in the cache.


setText

public BitmapFont.TextBounds setText(CharSequence str,
                                     float x,
                                     float y)
Clears any cached glyphs and adds glyphs for the specified text.

See Also:
addText(CharSequence, float, float, int, int)

setText

public BitmapFont.TextBounds setText(CharSequence str,
                                     float x,
                                     float y,
                                     int start,
                                     int end)
Clears any cached glyphs and adds glyphs for the specified text.

See Also:
addText(CharSequence, float, float, int, int)

addText

public BitmapFont.TextBounds addText(CharSequence str,
                                     float x,
                                     float y)
Adds glyphs for the specified text.

See Also:
addText(CharSequence, float, float, int, int)

addText

public BitmapFont.TextBounds addText(CharSequence str,
                                     float x,
                                     float y,
                                     int start,
                                     int end)
Adds glyphs for the the specified text.

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(CharSequence str,
                                              float x,
                                              float y)
Clears any cached glyphs and adds glyphs for the specified text, which may contain newlines (\n).

See Also:
#addMultiLineText(CharSequence, float, float, float, HAlignment)

setMultiLineText

public BitmapFont.TextBounds setMultiLineText(CharSequence str,
                                              float x,
                                              float y,
                                              float alignmentWidth,
                                              BitmapFont.HAlignment alignment)
Clears any cached glyphs and adds glyphs for the specified text, which may contain newlines (\n).

See Also:
#addMultiLineText(CharSequence, float, float, float, HAlignment)

addMultiLineText

public BitmapFont.TextBounds addMultiLineText(CharSequence str,
                                              float x,
                                              float y)
Adds glyphs for the specified text, which may contain newlines (\n).

See Also:
#addMultiLineText(CharSequence, float, float, float, HAlignment)

addMultiLineText

public BitmapFont.TextBounds addMultiLineText(CharSequence str,
                                              float x,
                                              float y,
                                              float alignmentWidth,
                                              BitmapFont.HAlignment alignment)
Adds glyphs for the specified text, which may contain newlines (\n). 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).
alignment - The horizontal alignment of wrapped line.
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(CharSequence str,
                                            float x,
                                            float y,
                                            float wrapWidth)
Clears any cached glyphs and adds glyphs for the specified text, which may contain newlines (\n) and is automatically wrapped within the specified width.

See Also:
#addWrappedText(CharSequence, float, float, float, HAlignment)

setWrappedText

public BitmapFont.TextBounds setWrappedText(CharSequence str,
                                            float x,
                                            float y,
                                            float wrapWidth,
                                            BitmapFont.HAlignment alignment)
Clears any cached glyphs and adds glyphs for the specified text, which may contain newlines (\n) and is automatically wrapped within the specified width.

See Also:
#addWrappedText(CharSequence, float, float, float, HAlignment)

addWrappedText

public BitmapFont.TextBounds addWrappedText(CharSequence str,
                                            float x,
                                            float y,
                                            float wrapWidth)
Adds glyphs for the specified text, which may contain newlines (\n) and is automatically wrapped within the specified width.

See Also:
#addWrappedText(CharSequence, float, float, float, HAlignment)

addWrappedText

public BitmapFont.TextBounds addWrappedText(CharSequence str,
                                            float x,
                                            float y,
                                            float wrapWidth,
                                            BitmapFont.HAlignment alignment)
Adds glyphs for the specified text, which may contain newlines (\n) and is automatically wrapped within 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).
alignment - The horizontal alignment of wrapped line.
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()

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.

getVertices

public float[] getVertices()

getVertices

public float[] getVertices(int page)


Copyright © 2013. All Rights Reserved.