Using bitmap fonts in starling?

How do you use bitmap font’s in starling? I generated a bitmap font in bmfont but have no idea how to use it in my project.

Hopefully this helps someone else because I could not find any documentation or how to. This is how I got it to render the bitmap font:

I loaded the font in my asset loader class like so:

var silomFontTexture:Texture = Texture.fromBitmapData(Assets.getBitmapData("assets/fonts/silom_0.png"), false);
var silomFontXml:Xml = Xml.parse(Assets.getText("assets/fonts/silom.fnt")).firstElement();

var silom:BitmapFont = new BitmapFont(silomFontTexture,silomFontXml);
TextField.registerBitmapFont(silom,'silom');

After registering the bitmap font I am now able to use it in any textField like this:

var textField:TextField = new TextField(100, 20, "Hello World");
textField.fontName = "silom";
textField.color = 0xffffff;
textField.fontSize = 18;
textField.x = 50;
textField.y=50;
1 Like

Is that silom.fnt file an XML ? And if so would you mind sharing the structure. I’m trying to use a Bitmap font for character 0 to 9 but getting little luck.
Thank you.

This is from a different font but it’s the same structure. Basically the font is being treated like a sprite sheet. This is the bitmap:

The XML:

https://www.dropbox.com/s/cm7tf5j351g1irp/mk3.fnt?dl=0

I see, can the fonts have fill with color ? And how do you go about generating that file, is it from the mentioned software bmfont ?

Tried to use this by :

import starling.textures.Texture;

var silomFontTexture:Texture = Texture.fromBitmapData(Assets.getBitmapData( etc...

but getting :
C:/HaxeToolkit/haxe/lib/starling/1,8,10/starling/textures/Texture.hx:470: characters 28-58 : Accessing this field requires flash version 11.8 (use -swf-version 11.8)

And -swf-version 11.8 added to the compile options is throwing out an error also. Tricky stuff.

EDIT 1: compiling to flash and using latest openfl from haxelib

yes the file was generated with bmfont you can grab the software here:
http://www.angelcode.com/products/bmfont/

I don’t know what the rest of your code looks like but be sure to import these as well:
import openfl.display.BitmapData;
import starling.textures.Texture;
import starling.textures.TextureAtlas;
import starling.utils.AssetManager;

Also be sure to be on the latest version of Starling I see you are running 1.8.1 current is 1.8.9.

Now I have not compiled to flash but I know this works with html5,mac and ios targets for sure.

My code looks like this:

var futuraFontTexture:Texture = Texture.fromBitmapData(Assets.getBitmapData("assets/fonts/futura_0.png"), false);
var futuraFontXml:Xml = Xml.parse(Assets.getText("assets/fonts/futura.fnt")).firstElement();

 var futura:BitmapFont = new BitmapFont(futuraFontTexture,futuraFontXml);
TextField.registerBitmapFont(futura,'futura');

Game.assets.addTextureAtlas('futura', new TextureAtlas(futuraFontTexture, futuraFontXml));

One other thing, does the starling sample run for you on the flash target?

Now that you mentioned, if you’re talking about the three samples that come with the lib:

Demo and particle-demo both throw:

VerifyError: Error #1014: Class flash.display3D.textures::RectangleTexture could not be found.

at starling.textures::Texture$/fromBitmapData()
at starling.events::TouchMarker/createTexture()
at starling.events::TouchMarker()
at starling.events::TouchProcessor/set_simulateMultitouch()
at starling.core::Starling/initialize()
at starling.core::Starling/onContextCreated()

and scaffold throws:

Warning: The Scaffold has not been completely ported and is not expected to work
src/Scaffold.hx:128: characters 30-48 : Class<openfl.utils.ByteArrayData> has no field fromFile

Running 1.8.10 according to haxelib, should I be on .9 ?

I seem to be experiencing issues compiling to flash target myself but it’s different from you:

#1063: Argument count mismatch on flash.display::Stage3D/requestContext3D(). Expected 0, got 2.
at MethodInfo-3752()
at MethodInfo-424()
at MethodInfo-420()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at SetIntervalTimer/onTimer()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()

Are you experiencing issues with other targets?

Does this help?

https://forum.starling-framework.org/topic/some-problem-with-flash-player-111-and-starling

Set a higher Flash SWF version?

“Set a higher Flash SWF version?” <-- ??
Is this related to "-swf-version 11.8 " I’m getting , and how to I do that in OpenFL. This is the first I read about it.

On the command-line:

openfl test flash --app-swf-version=13

In XML:

<app swf-version="13" />

Now that Flash Player on Linux has been updated, I think it’s appropriate to improve the default version of Flash we use, so I’ve updated Lime’s default version for the next release:

1 Like

That allowed for Frank_Hernandez code to run, demos started throwing a lot more stuff though. Must investigate.
Thanks singmajesty. Didn’t know one could do that.

Didn’t work for me I am still getting the error even after specifying the flash version, but that is ok I am not targeting flash at all in my applications. But looks like franky’s issue remains.