Fonts and text
A font is a file that defines the characters and sometimes special glyphs and symbols that can be printed on the screen. Fonts are typically defined as vectors. Because AndEngine and the OpenGL library in general don't work with vectors, we must first create a raster or bitmap font. We can imagine it as printing the entire alphabet with special characters using a font of our choice on an image and cutting out the letters. Afterwards, we create words using these cut-outs.
The following code shows how we load the font in the ResourceManager
class:
//font public Font font; public void loadFont() { font = FontFactory.createStroke(activity.getFontManager(), activity.getTextureManager(), 256, 256, Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD), 50, true, Color.WHITE_ABGR_PACKED_INT, 2, Color.BLACK_ABGR_PACKED_INT); font.load(); }
The first parameter passed is the FontManager
class. It's an AndEngine class that takes care of managing the fonts. The second parameter...