Back to project page tetris-android.
The source code is released under:
MIT License
If you think the Android project tetris-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.badlogic.androidgames.framework.gl; // w w w . java 2 s. c o m public class Font { public final Texture texture; public final int glyphWidth; public final int glyphHeight; public final TextureRegion[] glyphs = new TextureRegion[96]; public Font(Texture texture, int offsetX, int offsetY, int glyphsPerRow, int glyphWidth, int glyphHeight) { this.texture = texture; this.glyphWidth = glyphWidth; this.glyphHeight = glyphHeight; int x = offsetX; int y = offsetY; for(int i = 0; i < 96; i++) { glyphs[i] = new TextureRegion(texture, x, y, glyphWidth, glyphHeight); x += glyphWidth; if(x == offsetX + glyphsPerRow * glyphWidth) { x = offsetX; y += glyphHeight; } } } public void drawText(SpriteBatcher batcher, String text, float x, float y) { int len = text.length(); for(int i = 0; i < len; i++) { int c = text.charAt(i) - ' '; if(c < 0 || c > glyphs.length - 1) continue; TextureRegion glyph = glyphs[c]; batcher.drawSprite(x, y, glyphWidth, glyphHeight, glyph,1); x += glyphWidth; } } }