Unicode Bitmap Font

Topics: Windows Phone 8
Oct 29, 2013 at 7:39 AM
Edited Oct 29, 2013 at 7:52 AM
Dear,

I am new to Cocos2dxna, write a small game for windows phone 8. I want to create a bitmap font and compile it to xnb format. A bitmap font has 2 files: .png and .fnt file. Could you show me how to create custom font with regional character depend on my language. Then how to compile them to 2 xnb file ( I dont know how to process fnt file ???). I am using windows 8.

Thanks so much.
Tom
Coordinator
Oct 29, 2013 at 5:40 PM
Hello

First you make the PNG file which is your atlas with the Unicode characters on it.

Then you can just take your FNT file from the bitmap font tool and embed it as embedded content in your game. Then open the fnt file as a stream and send that stream to the BitMapFont loading code.

Otherwise you need to get on an XNA box and use the custom content pipeline builders to build the FNT file into XNB. The PNG atlas is just another texture.

When you process the FNT file as an embedded stream, make sure the FNT file has a path to the PNG atlas file that is correct.
Feb 26, 2014 at 4:11 PM
"Then you can just take your FNT file from the bitmap font tool and embed it as embedded content in your game. Then open the fnt file as a stream and send that stream to the BitMapFont loading code. "

Do you have an example of this you can share? I have a similar problem as Tom did, and I'm unable to build an XNB from my FNT file.
From some other posts I saw, it sounds like the recommended approach is to read from a Stream anyway?

What is the "BitmapFont loading code" you refer to?

Thanks very much!
Coordinator
Feb 27, 2014 at 4:58 AM
public static CCBMFontConfiguration Create(string fntFile)

this method in the CCBMFontConfiguration class will create the BM font description from a file. This file can be content managed (xnb) or it can be a literal file reference.

let us say that you have the raw FNT file and no xnb content encoding. then you can read your stream into memory and use:
    public CCBMFontConfiguration(string data, string fntFile)
    {
        InitWithString(data, fntFile);
    }
Mar 26, 2014 at 9:12 AM
Edited Mar 26, 2014 at 9:15 AM
i'm trying to use CCBMFontConfiguration but it's make a error like:
"An exception of type 'Microsoft.Xna.Framework.Content.ContentLoadException' occurred in cocos2d-xna.DLL but was not handled in user code
Additional information: Failed to load the asset file from Villa.fnt"

I know it's may be fnt.xnb but in window phone 8 i can't:
"
var fontFilePath = Path.Combine(Content.RootDirectory, "CourierNew32.fnt");
var fontFile = FontLoader.Load(fontFilePath);
var fontTexture = Content.Load<Texture2D>("CourierNew32_0.png");
"

and anything else, please help me :D

or something can show some vietnamese word. Thanks so much :D
Coordinator
Mar 26, 2014 at 3:28 PM
Here is the test/sample that demonstrates the use of bitmap fonts:

https://github.com/Cocos2DXNA/cocos2d-xna/blob/master/tests/tests/classes/tests/LabelTest/BMFontUnicode.cs

On WP8 you will have a CourierNew32.fnt.xnb file if you produced the assets using the XNA content builder project. If not, then you will have a CourerNew32.fnt file that you will need to load explicitly as a stream and send that to the font loader.