import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
\r
/**\r
- * <p>\r
- * A BitmapFont is used to load and render AngleCode bitmap font files. The AngleCode bitmap font consists of 2 files, the .fnt\r
- * file which must be saved with text encoding (not xml or binary!) and the bitmap file holding the glyphs, usually in .png\r
- * format.\r
- * </p>\r
- * \r
- * <p>\r
- * This implementation currently only supports a single glyph page.\r
- * </p>\r
- * \r
- * <p>\r
+ * Loads and renders AngleCode BMFont files. The bitmap font consists of 2 files: the .fnt file which must be saved with text\r
+ * encoding (not xml or binary!) and the bitmap file holding the glyphs, usually in .png format. <br>\r
+ * <br>\r
+ * This implementation currently only supports a single glyph page. <br>\r
+ * <br>\r
* To draw text with this class you need to call one of the draw() methods together with a {@link SpriteBatch}. The SpriteBatch\r
- * must be in rendering mode, that is, {@link SpriteBatch#begin()} must have been called before drawing\r
- * </p>\r
- * \r
- * <p>\r
- * Additionally you can cache text in a {@link BitmapFontCache} for faster rendering of static text\r
- * </p>\r
- * \r
- * <p>\r
- * A BitmapFont is managed. You need to call the {@link #dispose()} method when you no longer need it\r
- * </p>\r
- * \r
- * <p>\r
- * The code is heavily based on Matthias Mann's TWL BitmapFont class. Thanks for sharing Matthias :)\r
- * </p>\r
- * \r
- * @author nathan.sweet\r
- * \r
+ * must be in rendering mode, that is, {@link SpriteBatch#begin()} must have been called before drawing <br>\r
+ * <br>\r
+ * Additionally you can cache text in a {@link BitmapFontCache} for faster rendering of static text. <br>\r
+ * <br>\r
+ * A BitmapFont is managed. You need to call the {@link #dispose()} method when you no longer need it. <br>\r
+ * <br>\r
+ * The code is heavily based on Matthias Mann's TWL BitmapFont class. Thanks for sharing, Matthias! :)\r
+ * @author Nathan Sweet <misc@n4te.com>\r
*/\r
public class BitmapFont {\r
private static final int LOG2_PAGE_SIZE = 9;\r
private static final int PAGE_SIZE = 1 << LOG2_PAGE_SIZE;\r
private static final int PAGES = 0x10000 / PAGE_SIZE;\r
\r
- public final Texture texture;\r
+ private final Texture texture;\r
private final Glyph[][] glyphs = new Glyph[PAGES][];\r
private int lineHeight;\r
private int baseLine;\r
/**\r
* Creates a new BitmapFont instance based on a .fnt file and an image file holding the page with glyphs. Currently only\r
* supports single page AngleCode fonts.\r
- * \r
* @param fontFile The font file\r
- * @param imageFile the image file\r
+ * @param imageFile The image file\r
*/\r
public BitmapFont (FileHandle fontFile, FileHandle imageFile) {\r
texture = Gdx.graphics.newTexture(imageFile, TextureFilter.Linear, TextureFilter.Linear, TextureWrap.ClampToEdge,\r
/**\r
* Draws the given string at the given position with the given color. You can only call this between\r
* {@link SpriteBatch#begin()}/{@link SpriteBatch#end()}.\r
- * \r
* @param spriteBatch The {@link SpriteBatch} to use\r
* @param str The string\r
* @param x The x position of the left most character\r
- * @param y The y position of the left most character's top left corner.\r
+ * @param y The y position of the left most character's top left corner\r
* @param color The color\r
* @return the width of the rendered string\r
*/\r
/**\r
* Draws the given string at the given position with the given color. You can only call this between\r
* {@link SpriteBatch#begin()}/{@link SpriteBatch#end()}.\r
- * \r
* @param spriteBatch The {@link SpriteBatch} to use\r
* @param str The string\r
* @param x The x position of the left most character\r
- * @param y The y position of the left most character's top left corner.\r
+ * @param y The y position of the left most character's top left corner\r
* @param color The color\r
* @param start the first character of the string to draw\r
- * @param the last character of the string to draw\r
+ * @param end the last character of the string to draw\r
* @return the width of the rendered string\r
*/\r
public int draw (SpriteBatch spriteBatch, CharSequence str, int x, int y, Color color, int start, int end) {\r
\r
/**\r
* Draws the given string at the given position with the given color. The position coincides with the top left corner of the\r
- * first line's glyph. The method interprets new lines. You can only call this between {@link SpriteBatch#begin()}/\r
+ * first line's glyph. This method interprets new lines. You can only call this between {@link SpriteBatch#begin()}/\r
* {@link SpriteBatch#end()}.\r
- * \r
* @param spriteBatch The {@link SpriteBatch} to use\r
* @param str The string\r
* @param x The x position of the left most character of the first line\r
* @param y The y position of the left most character's top left corner of the first line\r
* @param color The color\r
- * @return\r
+ * @return The height of the rendered string\r
*/\r
public int drawMultiLineText (SpriteBatch spriteBatch, CharSequence str, int x, int y, Color color) {\r
return drawMultiLineText(spriteBatch, str, x, y, color, 0, HAlignment.LEFT);\r
}\r
\r
/**\r
- * <p>\r
* Draws the given string at the given position with the given color. The position coincides with the top left corner of the\r
* first line's glyph. The method interprets new lines. You can only call this between {@link SpriteBatch#begin()}/\r
- * {@link SpriteBatch#end()}.\r
- * </p>\r
- * <p>\r
+ * {@link SpriteBatch#end()}. <br>\r
+ * <br>\r
* You can specify the horizontal alignment of the text with the <code>alignmentWidth</code> and <code>alignment</code>\r
* parameters. The first parameter specifies the width of the rectangle the text should be aligned in (x to x +\r
* alignmentWidth). The second parameter specifies the alignment itself.\r
- * \r
* @param spriteBatch The {@link SpriteBatch} to use\r
* @param str The string\r
* @param x The x position of the left most character of the first line\r
* @param color The color\r
* @param alignmentWidth The alignment width\r
* @param alignment The horizontal alignment\r
- * @return the height of the multiline text\r
+ * @return The height of the multiline text\r
*/\r
public int drawMultiLineText (SpriteBatch spriteBatch, CharSequence str, int x, int y, Color color, int alignmentWidth,\r
HAlignment alignment) {\r
int start = 0;\r
int numLines = 0;\r
- while (start < str.length()) {\r
+ int length = str.length();\r
+ while (start < length) {\r
int lineEnd = indexOf(str, '\n', start);\r
int xOffset = 0;\r
if (alignment != HAlignment.LEFT) {\r
return numLines * lineHeight;\r
}\r
\r
+ /**\r
+ * Draws the given string at the given position with the given color. The position coincides with the top left corner of the\r
+ * first line's glyph. This method interprets new lines and causes the text to wrap at spaces based on the given\r
+ * <code>wrapWidth</code>. You can only call this between {@link SpriteBatch#begin()}/ {@link SpriteBatch#end()}.\r
+ * @param spriteBatch The {@link SpriteBatch} to use\r
+ * @param str The string\r
+ * @param x The x position of the left most character of the first line\r
+ * @param y The y position of the left most character's top left corner of the first line\r
+ * @param color The color\r
+ * @param wrapWidth The wrap width\r
+ * @return the height of the rendered string\r
+ */\r
+ public int drawWrappedText (SpriteBatch spriteBatch, CharSequence str, int x, int y, Color color, int wrapWidth) {\r
+ return drawWrappedText(spriteBatch, str, x, y, color, wrapWidth, HAlignment.LEFT);\r
+ }\r
+\r
+ /**\r
+ * Draws the given string at the given position with the given color. The position coincides with the top left corner of the\r
+ * first line's glyph. This method interprets new lines and causes the text to wrap at spaces based on the given\r
+ * <code>wrapWidth</code>. You can only call this between {@link SpriteBatch#begin()}/ {@link SpriteBatch#end()}.<br>\r
+ * <br>\r
+ * You can specify the horizontal alignment of the text within the <code>wrapWidth</code> by using the <code>alignment</code>\r
+ * parameter.\r
+ * @param spriteBatch The {@link SpriteBatch} to use\r
+ * @param str The string\r
+ * @param x The x position of the left most character of the first line\r
+ * @param y The y position of the left most character's top left corner of the first line\r
+ * @param color The color\r
+ * @param wrapWidth The wrap width\r
+ * @return the height of the rendered string\r
+ */\r
+ public int drawWrappedText (SpriteBatch spriteBatch, CharSequence str, int x, int y, Color color, int wrapWidth,\r
+ HAlignment alignment) {\r
+ int start = 0;\r
+ int numLines = 0;\r
+ int length = str.length();\r
+ while (start < length) {\r
+ int lineEnd = start + computeVisibleGlpyhs(str, start, indexOf(str, '\n', start), wrapWidth);\r
+ if (lineEnd < length) {\r
+ while (lineEnd > start) {\r
+ char ch = str.charAt(lineEnd);\r
+ if (ch == ' ' || ch == '\n') break;\r
+ lineEnd--;\r
+ }\r
+ }\r
+ if (lineEnd == start) lineEnd++;\r
+ int xOffset = 0;\r
+ if (alignment != HAlignment.LEFT) {\r
+ int lineWidth = computeTextWidth(str, start, lineEnd);\r
+ xOffset = wrapWidth - lineWidth;\r
+ if (alignment == HAlignment.CENTER) xOffset /= 2;\r
+ }\r
+ draw(spriteBatch, str, x + xOffset, y, color, start, lineEnd);\r
+ start = lineEnd + 1;\r
+ y -= lineHeight;\r
+ numLines++;\r
+ }\r
+ return numLines * lineHeight;\r
+ }\r
+\r
private void addToCache (BitmapFontCache cache, CharSequence str, int x, int y, Color color, int start, int end) {\r
Glyph lastGlyph = null;\r
while (start < end) {\r
}\r
\r
/**\r
- * Creates a new {@link BitmapFontCache} to be used with {@link #cacheText()}.\r
- * @return The cache\r
+ * Creates a new {@link BitmapFontCache} to be used with {@link #cacheText(BitmapFontCache, CharSequence, int, int, Color)}.\r
+ * @return The new cache\r
*/\r
public BitmapFontCache newCache () {\r
return new BitmapFontCache(this.texture);\r
\r
/**\r
* Caches the given string at the given position with the given color in the provided {@link BitmapFontCache}.\r
- * \r
* @param cache The cache\r
* @param str The string\r
* @param x The x position of the left most character\r
- * @param y The y position of the left most character's top left corner.\r
+ * @param y The y position of the left most character's top left corner\r
* @param color The color\r
*/\r
public void cacheText (BitmapFontCache cache, CharSequence str, int x, int y, Color color) {\r
\r
/**\r
* Caches the given string at the given position with the given color in the provided {@link BitmapFontCache}.\r
- * \r
* @param cache The cache\r
* @param str The string\r
* @param x The x position of the left most character\r
- * @param y The y position of the left most character's top left corner.\r
+ * @param y The y position of the left most character's top left corner\r
* @param color The color\r
- * @param start the first character of the string to draw\r
- * @param the last character of the string to draw\r
+ * @param start The first character of the string to draw\r
+ * @param end The last character of the string to draw\r
*/\r
public void cacheText (BitmapFontCache cache, CharSequence str, int x, int y, Color color, int start, int end) {\r
cache.reset(end - start);\r
/**\r
* Caches the given string at the given position with the given color in the provided {@link BitmapFontCache}. The position\r
* coincides with the top left corner of the first line's glyph. The method interprets new lines.\r
- * \r
- * @param spriteBatch The {@link SpriteBatch} to use\r
+ * @param cache The cache\r
* @param str The string\r
* @param x The x position of the left most character of the first line\r
* @param y The y position of the left most character's top left corner of the first line\r
}\r
\r
/**\r
- * <p>\r
* Caches the given string at the given position with the given color in the provided {@link BitmapFontCache}. The position\r
- * coincides with the top left corner of the first line's glyph. The method interprets new lines.\r
- * </p>\r
- * <p>\r
+ * coincides with the top left corner of the first line's glyph. The method interprets new lines. <br>\r
+ * <br>\r
* You can specify the horizontal alignment of the text with the <code>alignmentWidth</code> and <code>alignment</code>\r
* parameters. The first parameter specifies the width of the rectangle the text should be aligned in (x to x +\r
* alignmentWidth). The second parameter specifies the alignment itself.\r
- * \r
* @param cache The cache\r
* @param str The string\r
* @param x The x position of the left most character of the first line\r
* @param alignmentWidth The alignment width\r
* @param alignment The horizontal alignment\r
*/\r
- public BitmapFontCache cacheMultiLineText (BitmapFontCache cache, CharSequence str, int x, int y, Color color,\r
- int alignmentWidth, HAlignment alignment) {\r
+ public void cacheMultiLineText (BitmapFontCache cache, CharSequence str, int x, int y, Color color, int alignmentWidth,\r
+ HAlignment alignment) {\r
int length = str.length();\r
cache.reset(length);\r
int start = 0;\r
}\r
cache.width = alignmentWidth;\r
cache.height = start - y;\r
- return cache;\r
}\r
\r
/**\r
- * Computes the strings width\r
+ * Caches the given string at the given position with the given color in the provided {@link BitmapFontCache}. The position\r
+ * coincides with the top left corner of the first line's glyph. This method interprets new lines and causes the text to wrap\r
+ * at spaces based on the given <code>wrapWidth</code>.\r
+ * @param cache The cache\r
+ * @param str The string\r
+ * @param x The x position of the left most character of the first line\r
+ * @param y The y position of the left most character's top left corner of the first line\r
+ * @param color The color\r
+ * @param wrapWidth The wrap width\r
+ */\r
+ public void cacheWrappedText (BitmapFontCache cache, CharSequence str, int x, int y, Color color, int wrapWidth) {\r
+ cacheWrappedText(cache, str, x, y, color, wrapWidth, HAlignment.LEFT);\r
+ }\r
+\r
+ /**\r
+ * Caches the given string at the given position with the given color in the provided {@link BitmapFontCache}. The position\r
+ * coincides with the top left corner of the first line's glyph. This method interprets new lines and causes the text to wrap\r
+ * at spaces based on the given <code>wrapWidth</code>. <br>\r
+ * <br>\r
+ * You can specify the horizontal alignment of the text within the <code>wrapWidth</code> by using the <code>alignment</code>\r
+ * parameter.\r
+ * @param cache The cache\r
+ * @param str The string\r
+ * @param x The x position of the left most character of the first line\r
+ * @param y The y position of the left most character's top left corner of the first line\r
+ * @param color The color\r
+ * @param wrapWidth The wrap width\r
+ */\r
+ public void cacheWrappedText (BitmapFontCache cache, CharSequence str, int x, int y, Color color, int wrapWidth,\r
+ HAlignment alignment) {\r
+ int length = str.length();\r
+ cache.reset(length);\r
+ int start = 0;\r
+ int numLines = 0;\r
+ while (start < length) {\r
+ int lineEnd = start + computeVisibleGlpyhs(str, start, indexOf(str, '\n', start), wrapWidth);\r
+ if (lineEnd < length) {\r
+ while (lineEnd > start) {\r
+ char ch = str.charAt(lineEnd);\r
+ if (ch == ' ' || ch == '\n') break;\r
+ lineEnd--;\r
+ }\r
+ }\r
+ if (lineEnd == start) lineEnd++;\r
+ int xOffset = 0;\r
+ if (alignment != HAlignment.LEFT) {\r
+ int lineWidth = computeTextWidth(str, start, lineEnd);\r
+ xOffset = wrapWidth - lineWidth;\r
+ if (alignment == HAlignment.CENTER) xOffset /= 2;\r
+ }\r
+ addToCache(cache, str, x + xOffset, y, color, start, lineEnd);\r
+ start = lineEnd + 1;\r
+ y -= lineHeight;\r
+ numLines++;\r
+ }\r
+ cache.width = wrapWidth;\r
+ cache.height = start - y;\r
+ }\r
+\r
+ /**\r
+ * Computes the width of the string.\r
* @param str The string\r
* @return the width\r
*/\r
}\r
\r
/**\r
- * Computes the string with\r
+ * Computes the width of the string.\r
* @param str the string\r
- * @param start the first character index\r
- * @param end the last character index (exclusive)\r
- * @return the string width\r
+ * @param start The first character index\r
+ * @param end The last character index (exclusive)\r
+ * @return The string width\r
*/\r
public int computeTextWidth (CharSequence str, int start, int end) {\r
int width = 0;\r
/**\r
* Returns the number of characters that can be rendered given the available width.\r
* @param str The string\r
- * @param start the start index of the first character\r
- * @param end the index of the last character exclusive\r
+ * @param start The start index of the first character\r
+ * @param end The index of the last character (exclusive)\r
* @param availableWidth the available width\r
- * @return the number of characters that fit into availableWdith\r
+ * @return The number of characters that fit into availableWdith\r
*/\r
public int computeVisibleGlpyhs (CharSequence str, int start, int end, int availableWidth) {\r
int index = start;\r
}\r
\r
/**\r
- * Computes the maximum width of the multiline string\r
- * @param str the string\r
- * @return the maximum width\r
+ * Computes the maximum width of the string, respecting newlines.\r
+ * @param str The string\r
+ * @return The maximum width\r
*/\r
public int computeMultiLineTextWidth (CharSequence str) {\r
int start = 0;\r
int width = 0;\r
- while (start < str.length()) {\r
+ int length = str.length();\r
+ while (start < length) {\r
int lineEnd = indexOf(str, '\n', start);\r
int lineWidth = computeTextWidth(str, start, lineEnd);\r
width = Math.max(width, lineWidth);\r
}\r
\r
/**\r
- * @return the glyph texture\r
+ * @return The glyph texture\r
*/\r
public Texture getTexture () {\r
return texture;\r
}\r
\r
/**\r
- * @return the base line offset\r
+ * @return The baseline offset, which is the distance from the drawing position to the line that most glyphs sit on\r
*/\r
public int getBaseLine () {\r
return baseLine;\r
}\r
\r
/**\r
- * @return the line height\r
+ * @return The line height, which is the distance from one line of text to the next\r
*/\r
public int getLineHeight () {\r
return lineHeight;\r
}\r
\r
/**\r
- * @return the width of the space character\r
+ * @return The width of the space character\r
*/\r
public int getSpaceWidth () {\r
return spaceWidth;\r
}\r
\r
- public int getEM () {\r
- return lineHeight;\r
- }\r
-\r
- public int getEX () {\r
+ /**\r
+ * @return The x-height, which is the typical height of lowercase characters\r
+ */\r
+ public int getXHeight () {\r
return ex;\r
}\r
\r
+ /**\r
+ * @return The cap height, which is the typical height of uppercase characters\r
+ */\r
public int getCapHeight () {\r
return capHeight;\r
}\r
package com.badlogic.gdx.graphics;\r
\r
/**\r
- * <p>\r
- * A BitmapFontCache caches glyph geometry produced by a call to one of the {@link BitmapFontCache#cacheText()} methods. It\r
- * provides a fast way to render static text.\r
- * </p>\r
- * \r
- * <p>\r
- * The code is heavily based on Matthias Mann's TWL BitmapFont class. Thanks for sharing Matthias :)\r
- * </p>\r
- * \r
- * @author nathan.sweet\r
- * \r
+ * A BitmapFontCache caches glyph geometry produced by a call to one of the\r
+ * {@link BitmapFont#cacheText(BitmapFontCache, CharSequence, int, int, Color)} methods. It caches the glyph geometry, providing a\r
+ * fast way to render static text. <br>\r
+ * <br>\r
+ * The code is heavily based on Matthias Mann's TWL BitmapFont class. Thanks for sharing, Matthias! :)\r
+ * @author Nathan Sweet <misc@n4te.com>\r
+ * @author Matthias Mann\r
*/\r
public class BitmapFontCache {\r
private final Texture texture;\r
}\r
\r
/**\r
- * Sets the position of the text\r
- * @param x the x coordinate\r
- * @param y the y coodinate\r
+ * Sets the position of the text, relative to the position when the cached text was created.\r
+ * @param x The x coordinate\r
+ * @param y The y coodinate\r
*/\r
public void setPosition (float x, float y) {\r
translate(x - this.x, y - this.y);\r
}\r
\r
/**\r
- * Translates the text\r
- * @param xAmount the amount in x to move the text\r
- * @param yAmount the amount in y to move the text\r
+ * Sets the position of the text, relative to its current position.\r
+ * @param xAmount The amount in x to move the text\r
+ * @param yAmount The amount in y to move the text\r
*/\r
public void translate (float xAmount, float yAmount) {\r
if (xAmount == 0 && yAmount == 0) return;\r
\r
/**\r
* Sets the tint color of the text.\r
- * @param tint the {@link Color}\r
+ * @param tint The {@link Color}\r
*/\r
public void setColor (Color tint) {\r
final float color = tint.toFloatBits();\r
vertices[i] = color;\r
}\r
\r
+ /**\r
+ * Sets the tint color of the text.\r
+ */\r
+ public void setColor (float r, float g, float b, float a) {\r
+ int intBits = ((int)(255 * a) << 24) | ((int)(255 * b) << 16) | ((int)(255 * g) << 8) | ((int)(255 * r));\r
+ float color = Float.intBitsToFloat(intBits);\r
+ if (color == this.color) return;\r
+ this.color = color;\r
+ float[] vertices = this.vertices;\r
+ for (int i = 2, n = idx; i < n; i += 5)\r
+ vertices[i] = color;\r
+ }\r
+\r
void addGlyph (float x, float y, int srcX, int srcY, int srcWidth, int srcHeight, Color tint) {\r
final float x2 = x + srcWidth;\r
final float y2 = y + srcHeight;\r
}\r
\r
/**\r
- * Draws the contents of the given cache via a {@link SpriteBatch}. Must be called between a {@link SpriteBatch#begin()}/\r
+ * Draws the contents of the cache via a {@link SpriteBatch}. Must be called between a {@link SpriteBatch#begin()}/\r
* {@link SpriteBatch#end()} pair.\r
- * @param spriteBatch the SpriteBatch.\r
+ * @param spriteBatch The SpriteBatch\r
*/\r
public void draw (SpriteBatch spriteBatch) {\r
spriteBatch.draw(texture, vertices, 0, idx);\r
}\r
\r
/**\r
- * @return the width of the contained text\r
+ * @return The width of the contained text\r
*/\r
public int getWidth () {\r
return width;\r
}\r
\r
/**\r
- * @return the height of the contained text\r
+ * @return The height of the contained text\r
*/\r
public int getHeight () {\r
return height;\r
}\r
\r
/**\r
- * @return the x coordinate of the contained text\r
+ * @return The x coordinate of the contained text, relative to the position when the cached text was created\r
*/\r
public float getX () {\r
return x;\r
}\r
\r
/**\r
- * @return the y coordinate of the contained text\r
+ * @return The y coordinate of the contained text, relative to the position when the cached text was created\r
*/\r
public float getY () {\r
return y;\r
import com.badlogic.gdx.graphics.GL10;\r
import com.badlogic.gdx.graphics.Sprite;\r
import com.badlogic.gdx.graphics.SpriteBatch;\r
+import com.badlogic.gdx.graphics.BitmapFont.HAlignment;\r
import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
\r
private SpriteBatch spriteBatch;\r
private BitmapFont font;\r
private Sprite logoSprite;\r
- private Color blue = new Color(0, 0, 1, 0.5f);\r
- private BitmapFontCache cache1, cache2, cache3, cache4;\r
+ private Color red = new Color(1, 0, 0, 0.5f);\r
+ private BitmapFontCache cache1, cache2, cache3, cache4, cache5;\r
int renderMode;\r
+ private float alpha;\r
\r
public void surfaceCreated () {\r
if (spriteBatch != null) return;\r
return false;\r
}\r
});\r
+\r
cache1 = font.newCache();\r
cache2 = font.newCache();\r
cache3 = font.newCache();\r
cache4 = font.newCache();\r
+ cache5 = font.newCache();\r
\r
font.cacheText(cache1, "(cached)", 10, 76, Color.WHITE);\r
\r
font.cacheMultiLineText(cache2, text, 5, 310, Color.RED, 470, BitmapFont.HAlignment.LEFT);\r
\r
text = "How quickly\ndaft jumping zebras vex.";\r
- font.cacheMultiLineText(cache3, text, 5, 210, blue, 470, BitmapFont.HAlignment.CENTER);\r
+ font.cacheMultiLineText(cache3, text, 5, 210, Color.BLUE, 470, BitmapFont.HAlignment.CENTER);\r
\r
text = "Kerning: LYA moo";\r
font.cacheText(cache4, text, 210, 76, Color.WHITE, 0, text.length() - 3);\r
+\r
+ text = "Forsaking monastic tradition, twelve jovial friars gave\nup their vocation for a questionable existence on the flying trapeze.";\r
+ font.cacheWrappedText(cache5, text, 0, 310, red, 480, HAlignment.CENTER);\r
}\r
\r
public void surfaceChanged (int width, int height) {\r
}\r
\r
public void render () {\r
+ alpha = (alpha + Gdx.graphics.getDeltaTime() * 0.1f) % 1;\r
+\r
GL10 gl = Gdx.graphics.getGL10();\r
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
spriteBatch.begin();\r
}\r
\r
private void renderNormal () {\r
+ String text = "Forsaking monastic tradition, twelve jovial friars gave\nup their vocation for a questionable existence on the flying trapeze.";\r
+ red.a = alpha;\r
+ font.drawWrappedText(spriteBatch, text, 0, 310, red, 480, HAlignment.CENTER);\r
+ if (alpha > 0.66f) return;\r
+\r
font.draw(spriteBatch, "(normal)", 10, 76, Color.WHITE);\r
\r
- String text = "Sphinx of black quartz,\njudge my vow.";\r
+ text = "Sphinx of black quartz,\njudge my vow.";\r
font.drawMultiLineText(spriteBatch, text, 5, 310, Color.RED);\r
\r
text = "How quickly\ndaft jumping zebras vex.";\r
- font.drawMultiLineText(spriteBatch, text, 5, 210, blue, 470, BitmapFont.HAlignment.RIGHT);\r
+ font.drawMultiLineText(spriteBatch, text, 5, 210, Color.BLUE, 470, BitmapFont.HAlignment.RIGHT);\r
\r
text = "Kerning: LYA moo";\r
font.draw(spriteBatch, text, 210, 76, Color.WHITE, 0, text.length() - 3);\r
}\r
\r
private void renderCached () {\r
+ red.a = alpha;\r
+ cache5.setColor(red);\r
+ cache5.draw(spriteBatch);\r
+ if (alpha > 0.66f) return;\r
+\r
cache1.draw(spriteBatch);\r
cache2.draw(spriteBatch);\r
cache3.draw(spriteBatch);\r