How to use Font and Text in andEngine?

uncle Lem picture uncle Lem · Jul 16, 2012 · Viewed 12.4k times · Source

That's how I tried to do it:

fontTextureAtlas = new BitmapTextureAtlas(1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
font = FontFactory.createFromAsset(fontTextureAtlas,this,"times.ttf",45f,true,Color.WHITE);
getEngine().getTextureManager().loadTexture(fontTextureAtlas);

and then, in code:

Text text = new Text(10,10, font,"Some text");
scene.attachChild(text);

and all what I see is this:

black blocks instead of text

Also I tried to use new Font(fontTextureAtlas,Typeface.DEFAULT,45f,true,Color.WHITE); to initialize the font, but result was almost the same.

Does anyone know what I did wrong?

Answer

user874649 picture user874649 · Jul 16, 2012

Try adding font.load(); after getEngine().getTextureManager().loadTexture(fontTextureAtlas);

If that doesn't work try

getEngine().getFontManager().loadFont(font);