[added] Sprite constructor for easily creating a sprite with a texture region relative to another sprite's texture region.
private static final int PAGE_SIZE = 1 << LOG2_PAGE_SIZE;\r
private static final int PAGES = 0x10000 / PAGE_SIZE;\r
\r
- private final Texture texture;\r
+ final Texture texture;\r
+ final int lineHeight;\r
+ final int yOffset;\r
+ final int down;\r
+\r
private final Glyph[][] glyphs = new Glyph[PAGES][];\r
- private final int lineHeight;\r
private final int baseLine;\r
private final int spaceWidth;\r
private final int xHeight;\r
private final int capHeight;\r
- private final int yOffset;\r
- private final float down;\r
\r
/**\r
* Creates a new BitmapFont instance based on a .fnt file and an image file holding the page with glyphs. Currently only\r
glyph.xoffset = Integer.parseInt(tokens.nextToken());\r
tokens.nextToken();\r
if (flip)\r
- glyph.yoffset = Integer.parseInt(tokens.nextToken()) - lineHeight + baseLine;\r
+ glyph.yoffset = Integer.parseInt(tokens.nextToken());\r
else\r
glyph.yoffset = -(glyph.height + Integer.parseInt(tokens.nextToken()));\r
tokens.nextToken();\r
g = getGlyph('M');\r
capHeight = g != null ? g.height : 1;\r
\r
- yOffset = flip ? 0 : lineHeight - baseLine;\r
- down = flip ? 1 : -1;\r
+ yOffset = flip ? -baseLine : baseLine;\r
+ down = flip ? lineHeight : -lineHeight;\r
} catch (Exception ex) {\r
throw new GdxRuntimeException("Error loading font file: " + fontFile, ex);\r
} finally {\r
}\r
}\r
\r
- private Glyph getGlyph (char ch) {\r
+ Glyph getGlyph (char ch) {\r
Glyph[] page = glyphs[ch / PAGE_SIZE];\r
if (page != null) return page[ch & (PAGE_SIZE - 1)];\r
return null;\r
while (start < end) {\r
char ch = str.charAt(start++);\r
Glyph g = getGlyph(ch);\r
- if (g != null) {\r
- x += lastGlyph.getKerning(ch);\r
- lastGlyph = g;\r
- spriteBatch.draw(texture, x + lastGlyph.xoffset, y + lastGlyph.yoffset, lastGlyph.width, lastGlyph.height,\r
- lastGlyph.u, lastGlyph.v, lastGlyph.u2, lastGlyph.v2, color);\r
- x += g.xadvance;\r
- }\r
+ if (g == null) continue;\r
+ x += lastGlyph.getKerning(ch);\r
+ lastGlyph = g;\r
+ spriteBatch.draw(texture, x + lastGlyph.xoffset, y + lastGlyph.yoffset, lastGlyph.width, lastGlyph.height, lastGlyph.u,\r
+ lastGlyph.v, lastGlyph.u2, lastGlyph.v2, color);\r
+ x += g.xadvance;\r
}\r
return x - startX;\r
}\r
*/\r
public int drawMultiLineText (SpriteBatch spriteBatch, CharSequence str, int x, int y, Color color, int alignmentWidth,\r
HAlignment alignment) {\r
+ int down = this.down;\r
int start = 0;\r
int numLines = 0;\r
int length = str.length();\r
}\r
draw(spriteBatch, str, x + xOffset, y, color, start, lineEnd);\r
start = lineEnd + 1;\r
- y += lineHeight * down;\r
+ y += down;\r
numLines++;\r
}\r
return numLines * lineHeight;\r
*/\r
public int drawWrappedText (SpriteBatch spriteBatch, CharSequence str, int x, int y, Color color, int wrapWidth,\r
HAlignment alignment) {\r
+ int down = this.down;\r
int start = 0;\r
int numLines = 0;\r
int length = str.length();\r
}\r
draw(spriteBatch, str, x + xOffset, y, color, start, lineEnd);\r
start = lineEnd + 1;\r
- y += lineHeight * down;\r
+ y += down;\r
numLines++;\r
}\r
return numLines * lineHeight;\r
}\r
\r
- private int addToCache (BitmapFontCache cache, CharSequence str, int x, int y, float color, int start, int end) {\r
- Glyph lastGlyph = null;\r
- while (start < end) {\r
- lastGlyph = getGlyph(str.charAt(start++));\r
- if (lastGlyph != null) {\r
- cache.addGlyph(lastGlyph, x, y, color);\r
- x += lastGlyph.xadvance;\r
- break;\r
- }\r
- }\r
- while (start < end) {\r
- char ch = str.charAt(start++);\r
- Glyph g = getGlyph(ch);\r
- if (g != null) {\r
- x += lastGlyph.getKerning(ch);\r
- lastGlyph = g;\r
- cache.addGlyph(lastGlyph, x, y, color);\r
- x += g.xadvance;\r
- }\r
- }\r
- return x;\r
- }\r
-\r
- /**\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(texture);\r
- }\r
-\r
- /**\r
- * Caches the given string at the given position with the given color in the provided {@link BitmapFontCache}.\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 color The color\r
- */\r
- public void cacheText (BitmapFontCache cache, CharSequence str, int x, int y, Color color) {\r
- cacheText(cache, str, x, y, color, 0, str.length());\r
- }\r
-\r
- /**\r
- * Caches the given string at the given position with the given color in the provided {@link BitmapFontCache}.\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 tint The color\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 tint, int start, int end) {\r
- final float color = tint.toFloatBits();\r
- cache.reset(end - start);\r
- y += yOffset;\r
- cache.width = addToCache(cache, str, x, y, color, start, end);\r
- cache.height = lineHeight;\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. The method interprets new lines.\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
- */\r
- public void cacheMultiLineText (BitmapFontCache cache, CharSequence str, int x, int y, Color color) {\r
- cacheMultiLineText(cache, str, x, y, color, 0, 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. 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
- * @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 tint The color\r
- * @param alignmentWidth The alignment width\r
- * @param alignment The horizontal alignment\r
- */\r
- public void cacheMultiLineText (BitmapFontCache cache, CharSequence str, int x, int y, Color tint, int alignmentWidth,\r
- HAlignment alignment) {\r
- final float color = tint.toFloatBits();\r
- y += yOffset;\r
- int length = str.length();\r
- cache.reset(length);\r
- int start = 0;\r
- int numLines = 0;\r
- while (start < length) {\r
- int lineEnd = indexOf(str, '\n', start);\r
- int xOffset = 0;\r
- if (alignment != HAlignment.LEFT) {\r
- int lineWidth = computeTextWidth(str, start, lineEnd);\r
- xOffset = alignmentWidth - 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 * down;\r
- numLines++;\r
- }\r
- cache.width = alignmentWidth;\r
- cache.height = start - y;\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>. The wrapped text is left aligned.\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 tint The color\r
- * @param wrapWidth The wrap width\r
- */\r
- public void cacheWrappedText (BitmapFontCache cache, CharSequence str, int x, int y, Color tint, int wrapWidth,\r
- HAlignment alignment) {\r
- final float color = tint.toFloatBits();\r
- y += yOffset;\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 * down;\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
}\r
}\r
\r
- static private int indexOf (CharSequence text, char ch, int start) {\r
+ static int indexOf (CharSequence text, char ch, int start) {\r
final int n = text.length();\r
for (; start < n; start++)\r
if (text.charAt(start) == ch) return start;\r
package com.badlogic.gdx.graphics;\r
\r
import com.badlogic.gdx.graphics.BitmapFont.Glyph;\r
+import com.badlogic.gdx.graphics.BitmapFont.HAlignment;\r
\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
+ * A BitmapFontCache caches glyph geometry for a BitmapFont, providing a 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
+ private final BitmapFont font;\r
private float[] vertices;\r
private int idx;\r
int width, height;\r
private float x, y;\r
private float color;\r
\r
- BitmapFontCache (Texture texture) {\r
- this.texture = texture;\r
+ public BitmapFontCache (BitmapFont font) {\r
+ this.font = font;\r
}\r
\r
/**\r
vertices[i] = color;\r
}\r
\r
+ /**\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
+ */\r
+ public void draw (SpriteBatch spriteBatch) {\r
+ spriteBatch.draw(font.texture, vertices, 0, idx);\r
+ }\r
+\r
+ void reset (int glyphCount) {\r
+ x = 0;\r
+ y = 0;\r
+ idx = 0;\r
+\r
+ int vertexCount = glyphCount * 20;\r
+ if (vertices == null || vertices.length < vertexCount) vertices = new float[vertexCount];\r
+ }\r
+\r
+ private int addToCache (CharSequence str, int x, int y, float color, int start, int end) {\r
+ BitmapFont font = this.font;\r
+ Glyph lastGlyph = null;\r
+ while (start < end) {\r
+ lastGlyph = font.getGlyph(str.charAt(start++));\r
+ if (lastGlyph != null) {\r
+ addGlyph(lastGlyph, x, y, color);\r
+ x += lastGlyph.xadvance;\r
+ break;\r
+ }\r
+ }\r
+ while (start < end) {\r
+ char ch = str.charAt(start++);\r
+ Glyph g = font.getGlyph(ch);\r
+ if (g != null) {\r
+ x += lastGlyph.getKerning(ch);\r
+ lastGlyph = g;\r
+ addGlyph(lastGlyph, x, y, color);\r
+ x += g.xadvance;\r
+ }\r
+ }\r
+ return x;\r
+ }\r
+\r
void addGlyph (Glyph glyph, float x, float y, float color) {\r
x += glyph.xoffset;\r
y += glyph.yoffset;\r
}\r
\r
/**\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
+ * Caches the given string at the given position with the given color in the provided {@link BitmapFontCache}.\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 tint The color\r
*/\r
- public void draw (SpriteBatch spriteBatch) {\r
- spriteBatch.draw(texture, vertices, 0, idx);\r
+ public void setText (CharSequence str, int x, int y, Color tint) {\r
+ setText(str, x, y, tint, 0, str.length());\r
}\r
\r
- void reset (int glyphCount) {\r
- x = 0;\r
- y = 0;\r
- idx = 0;\r
+ /**\r
+ * Caches the given string at the given position with the given color in the provided {@link BitmapFontCache}.\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 tint The color\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 setText (CharSequence str, int x, int y, Color tint, int start, int end) {\r
+ final float color = tint.toFloatBits();\r
+ reset(end - start);\r
+ y += font.yOffset;\r
+ width = addToCache(str, x, y, color, start, end);\r
+ height = font.lineHeight;\r
+ }\r
\r
- int vertexCount = glyphCount * 20;\r
- if (vertices == null || vertices.length < vertexCount) vertices = new float[vertexCount];\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
+ * @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 tint The color\r
+ */\r
+ public void setMultiLineText (CharSequence str, int x, int y, Color tint) {\r
+ setMultiLineText(str, x, y, tint, 0, 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. 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
+ * @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 tint The color\r
+ * @param alignmentWidth The alignment width\r
+ * @param alignment The horizontal alignment\r
+ */\r
+ public void setMultiLineText (CharSequence str, int x, int y, Color tint, int alignmentWidth, HAlignment alignment) {\r
+ BitmapFont font = this.font;\r
+\r
+ int length = str.length();\r
+ reset(length);\r
+\r
+ final float color = tint.toFloatBits();\r
+ y += font.yOffset;\r
+ int down = font.down;\r
+\r
+ int start = 0;\r
+ int numLines = 0;\r
+ while (start < length) {\r
+ int lineEnd = BitmapFont.indexOf(str, '\n', start);\r
+ int xOffset = 0;\r
+ if (alignment != HAlignment.LEFT) {\r
+ int lineWidth = font.computeTextWidth(str, start, lineEnd);\r
+ xOffset = alignmentWidth - lineWidth;\r
+ if (alignment == HAlignment.CENTER) xOffset /= 2;\r
+ }\r
+ addToCache(str, x + xOffset, y, color, start, lineEnd);\r
+ start = lineEnd + 1;\r
+ y += down;\r
+ numLines++;\r
+ }\r
+ width = alignmentWidth;\r
+ height = start - y;\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>. The wrapped text is left aligned.\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 tint The color\r
+ * @param wrapWidth The wrap width\r
+ */\r
+ public void setWrappedText (CharSequence str, int x, int y, Color tint, int wrapWidth) {\r
+ setWrappedText(str, x, y, tint, 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 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 tint The color\r
+ * @param wrapWidth The wrap width\r
+ */\r
+ public void setWrappedText (CharSequence str, int x, int y, Color tint, int wrapWidth, HAlignment alignment) {\r
+ BitmapFont font = this.font;\r
+\r
+ int length = str.length();\r
+ reset(length);\r
+\r
+ final float color = tint.toFloatBits();\r
+ y += font.yOffset;\r
+ int down = font.down;\r
+\r
+ int start = 0;\r
+ int numLines = 0;\r
+ while (start < length) {\r
+ int lineEnd = start + font.computeVisibleGlpyhs(str, start, BitmapFont.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 = font.computeTextWidth(str, start, lineEnd);\r
+ xOffset = wrapWidth - lineWidth;\r
+ if (alignment == HAlignment.CENTER) xOffset /= 2;\r
+ }\r
+ addToCache(str, x + xOffset, y, color, start, lineEnd);\r
+ start = lineEnd + 1;\r
+ y += down;\r
+ numLines++;\r
+ }\r
+ width = wrapWidth;\r
+ height = start - y;\r
}\r
\r
/**\r
private boolean dirty;\r
\r
/**\r
- * Creates a sprite with both bounds and texture region equal to the size of the texture.\r
+ * Creates a sprite with width, height, and texture region equal to the size of the texture.\r
*/\r
public Sprite (Texture texture) {\r
this(texture, 0, 0, texture.getWidth(), texture.getHeight());\r
}\r
\r
/**\r
- * Creates a sprite with both bounds and texture region equal to the specified size. The texture region's upper left corner\r
+ * Creates a sprite with width, height, and texture region equal to the specified size. The texture region's upper left corner\r
* will be 0,0.\r
*/\r
public Sprite (Texture texture, int srcWidth, int srcHeight) {\r
}\r
\r
/**\r
- * Creates a sprite with both bounds and texture region equal to the specified size.\r
+ * Creates a sprite with width, height, and texture region equal to the specified size.\r
*/\r
public Sprite (Texture texture, int srcX, int srcY, int srcWidth, int srcHeight) {\r
if (texture == null) throw new IllegalArgumentException("texture cannot be null.");\r
}\r
\r
/**\r
+ * Creates a sprite with width, height, and texture region equal to the specified size, relative to specified sprite's texture\r
+ * region.\r
+ */\r
+ public Sprite (Sprite parent, int srcX, int srcY, int srcWidth, int srcHeight) {\r
+ this(parent.texture, (int)(srcX + parent.vertices[U1] * parent.texture.getWidth()), (int)(srcY + parent.vertices[V2]\r
+ * parent.texture.getHeight()), srcWidth, srcHeight);\r
+ }\r
+\r
+ /**\r
* Sets the size and position of the sprite when drawn, before scaling and rotation are applied. If origin, rotation, or scale\r
* are changed, it is slightly more efficient to set the bounds afterward.\r
*/\r
}\r
});\r
\r
- cache1 = font.newCache();\r
- cache2 = font.newCache();\r
- cache3 = font.newCache();\r
- cache4 = font.newCache();\r
- cache5 = font.newCache();\r
+ cache1 = new BitmapFontCache(font);\r
+ cache2 = new BitmapFontCache(font);\r
+ cache3 = new BitmapFontCache(font);\r
+ cache4 = new BitmapFontCache(font);\r
+ cache5 = new BitmapFontCache(font);\r
\r
- font.cacheText(cache1, "(cached)", 10, 320 - 76, Color.WHITE);\r
+ cache1.setText("(cached)", 10, 320 - 36, Color.WHITE);\r
\r
String text = "Sphinx of black quartz,\njudge my vow.";\r
- font.cacheMultiLineText(cache2, text, 5, 320 - 310, Color.RED);\r
+ cache2.setMultiLineText(text, 5, 320 - 270, Color.RED);\r
\r
text = "How quickly\ndaft jumping zebras vex.";\r
- font.cacheMultiLineText(cache3, text, 5, 320 - 210, Color.BLUE, 470, BitmapFont.HAlignment.CENTER);\r
+ cache3.setMultiLineText(text, 5, 320 - 170, Color.BLUE, 470, BitmapFont.HAlignment.CENTER);\r
\r
text = "Kerning: LYA moo";\r
- font.cacheText(cache4, text, 210, 320 - 76, Color.WHITE, 0, text.length() - 3);\r
+ cache4.setText(text, 210, 320 - 36, 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, 320 - 310, red, 480, HAlignment.CENTER);\r
+ cache5.setWrappedText(text, 0, 320 - 270, red, 480, HAlignment.CENTER);\r
}\r
\r
public void surfaceChanged (int width, int height) {\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, 320 - 310, red, 480, HAlignment.CENTER);\r
+ font.drawWrappedText(spriteBatch, text, 0, 320 - 270, red, 480, HAlignment.CENTER);\r
\r
- font.draw(spriteBatch, "(normal)", 10, 320 - 76, Color.WHITE);\r
+ font.draw(spriteBatch, "(normal)", 10, 320 - 36, Color.WHITE);\r
\r
if (alpha > 0.6f) return;\r
\r
text = "Sphinx of black quartz,\njudge my vow.";\r
- font.drawMultiLineText(spriteBatch, text, 5, 320 - 310, Color.RED);\r
+ font.drawMultiLineText(spriteBatch, text, 5, 320 - 270, Color.RED);\r
\r
text = "How quickly\ndaft jumping zebras vex.";\r
- font.drawMultiLineText(spriteBatch, text, 5, 320 - 210, Color.BLUE, 470, BitmapFont.HAlignment.RIGHT);\r
+ font.drawMultiLineText(spriteBatch, text, 5, 320 - 170, Color.BLUE, 470, BitmapFont.HAlignment.RIGHT);\r
\r
text = "Kerning: LYA moo";\r
- font.draw(spriteBatch, text, 210, 320 - 76, Color.WHITE, 0, text.length() - 3);\r
+ font.draw(spriteBatch, text, 210, 320 - 36, Color.WHITE, 0, text.length() - 3);\r
}\r
\r
private void renderCached () {\r
public void dispose () {\r
}\r
\r
- @Override public boolean needsGL20 () {\r
- // TODO Auto-generated method stub\r
+ public boolean needsGL20 () {\r
return false;\r
}\r
}\r
}\r
});\r
\r
- cache1 = font.newCache();\r
- cache2 = font.newCache();\r
- cache3 = font.newCache();\r
- cache4 = font.newCache();\r
- cache5 = font.newCache();\r
+ cache1 = new BitmapFontCache(font);\r
+ cache2 = new BitmapFontCache(font);\r
+ cache3 = new BitmapFontCache(font);\r
+ cache4 = new BitmapFontCache(font);\r
+ cache5 = new BitmapFontCache(font);\r
\r
- font.cacheText(cache1, "(cached)", 10, 76, Color.WHITE);\r
+ cache1.setText("(cached)", 10, 36, Color.WHITE);\r
\r
String text = "Sphinx of black quartz,\njudge my vow.";\r
- font.cacheMultiLineText(cache2, text, 5, 310, Color.RED);\r
+ cache2.setMultiLineText(text, 5, 270, Color.RED);\r
\r
text = "How quickly\ndaft jumping zebras vex.";\r
- font.cacheMultiLineText(cache3, text, 5, 210, Color.BLUE, 470, BitmapFont.HAlignment.CENTER);\r
+ cache3.setMultiLineText(text, 5, 170, 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
+ cache4.setText(text, 210, 36, 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
+ cache5.setWrappedText(text, 0, 270, red, 480, HAlignment.CENTER);\r
}\r
\r
public void surfaceChanged (int width, int height) {\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
+ font.drawWrappedText(spriteBatch, text, 0, 270, red, 480, HAlignment.CENTER);\r
\r
- font.draw(spriteBatch, "(normal)", 10, 76, Color.WHITE);\r
+ font.draw(spriteBatch, "(normal)", 10, 36, Color.WHITE);\r
\r
if (alpha > 0.6f) return;\r
\r
text = "Sphinx of black quartz,\njudge my vow.";\r
- font.drawMultiLineText(spriteBatch, text, 5, 310, Color.RED);\r
+ font.drawMultiLineText(spriteBatch, text, 5, 270, Color.RED);\r
\r
text = "How quickly\ndaft jumping zebras vex.";\r
- font.drawMultiLineText(spriteBatch, text, 5, 210, Color.BLUE, 470, BitmapFont.HAlignment.RIGHT);\r
+ font.drawMultiLineText(spriteBatch, text, 5, 170, 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
+ font.draw(spriteBatch, text, 210, 36, Color.WHITE, 0, text.length() - 3);\r
}\r
\r
private void renderCached () {\r
public void dispose () {\r
}\r
\r
- @Override public boolean needsGL20 () {\r
- // TODO Auto-generated method stub\r
+ public boolean needsGL20 () {\r
return false;\r
}\r
}\r