Loading bitmap font during runtime instead of during preload.

Hi,

I’m able to load images, sounds etc. during runtime but when trying to load bitmap font with the loader during runtime I’ve hit some issues. Been searching around and found no examples loading it that way but reading the documentation it seems that I should be able to do it. I’ve tried fonts from the phaser examples library so that should not be the problem.

This is essentially the code

                scene.load.bitmapFont("textName", "urlToImage", "urlToXml");
                    scene.load.once("complete", () => {
                         let text = scene.add.bitmapText(300, 300, "textName", "abc", 70);
                    });

Error I get:

Uncaught TypeError: String.fromCharCode is not a function
at ParseXMLBitmapFont (phaser.js:50654:29)
at BitmapFontFile.addToCache…etc

Seems like something goes bad during loading and therefore everything else after goes bad.
Would appreciate any help on this issue since I’m kind of stuck right now.

Cheers!
/C

:wave:

This is an odd error because String.fromCharCode() is a built-in function.

If it reached ParseXMLBitmapFont() then something has loaded.

Maybe break in the debugger and take a look.

Hi samme, thanks for your answer. Yes, I can actually see that stuff has been loaded from the xml-file. As I said earlier it doesn’t seem to matter which font I try. It always breaks on this line:

var letter = String.fromCharCode(charCode);

Seems like the String object here is equal to an empty string (“”) and therefore the fromCharCode method doesn’t exist. The question is, should it be possible to load the font at a later time than preload or is this a bug in the loading of bitmapFont?

It should be possible, and this doesn’t seem like a Phaser bug.

Is there anything in your code modifying String?

Good to know that it should be possible, I have searched through my project to see if any references to String can be found but found nothing. I will try some more breakpoints later and see if I can figure out what String is containing and when it changes to an empty string.