How to use font and text in andEngine?

Here is how I tried to do this:

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 the code:

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

and all i see is:

black blocks instead of text

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

Does anyone know what I did wrong?

+4
source share
3 answers

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

If this does not work, try

 getEngine().getFontManager().loadFont(font); 
+10
source

It works for me

 FontFactory.SetAssetBasePath("fontfolder/"); mFont = FontFactory.createFromAsset(mEngine.getFontManager(), mEngine.getTextureManager(), 256, 256, TextureOptions.BILINEAR, activity.getAssets(), "QUARTZMS.TTF", 32f, true, Color.YELLOW_ARGB_PACKED_INT); mFont.load(); 

Then I just add mText = new Text(25, 25, mFont, "Some Text",getVertexBufferObjectManager());

+3
source

I wrote a blog post in the text inside andengine that might help http://stuartmct.co.uk/2012/07/16/andengine-creating-and-using-text/

+2
source

All Articles