MaskedPixel Posted March 21, 2017 Share Posted March 21, 2017 Hi, I am trying to load a bitmap text font with PixiJS and I get this error: Uncaught TypeError: Cannot read property 'size' of undefined at e.updateText (BitmapText.js:99) at new e (BitmapText.js:99) The font is created with BMGlyph using the Cocos2d/BMFont settings with the font face forced to be "hudScoreFont". Here is how I load the font: loader.add("hudScoreFont", "assets/fonts/hudScoreFont.fnt"); And here is how I create the BitmapText object: let txtScore = new BitmapText("00", {font: "288px hudScoreFont"}); I can see that the fnt file has been downloaded, but the png of the font is never downloaded. If you have any insight as to what I might be doing wrong, please let me know! EDIT: I am using Pixi v. 4.4.2 Quote Link to comment Share on other sites More sharing options...
FakeWizard Posted March 21, 2017 Share Posted March 21, 2017 can you reveal a little bit more code as it's not clear whether the BitmapText is being instantiated correctly after all the assets have finished loading (?) Quote Link to comment Share on other sites More sharing options...
MaskedPixel Posted March 21, 2017 Author Share Posted March 21, 2017 Sure, this is written in haxe using a custom game engine though. Where the font is loaded: class PreloaderScene extends Scene { public function new() { super(); } override public function onBegin():Void { var loader = new Loader(); loader.add("hudScoreFont", "assets/fonts/hudScoreFont.fnt"); loader.load(onLoaded); } private function onLoaded(loader:ResourceLoader):Void { Turbo.director.unwindToScene(new GameplayScene()); } } Where the font is created: class GameplayScene extends Scene { public function new() { super(); } override public function onBegin():Void { _txtScore = new BitmapText("00", {font: "288px hudScoreFont", align: "center"}); container.addChild(_txtScore); } } So the PreloaderScene is loaded elsewhere. The onBegin funciton is called when the scene starts. The loader is created and load is called. onLoaded is passed to the load function of the loader and is called after the the loader is complete (I have verified that the fnt file is in fact stored in the loader object via console.log). Finally, the Gameplay scene is started and the bitmap text object is created. I have also verified that the font object is never created by doing console.log(BitmapText.fonts) and there are no fonts. So the error is somewhere in the loader and I'm unsure how to debug it beyond this point. Quote Link to comment Share on other sites More sharing options...
MaskedPixel Posted March 21, 2017 Author Share Posted March 21, 2017 And in case it is needed: here is the font file and png... hudScoreFont.fnt Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 21, 2017 Share Posted March 21, 2017 @MaskedPixel Looking at bitmapText resource loader, it supports only XML. Can you please look at it too and write the correct one? https://github.com/pixijs/pixi.js/blob/dev/src/loaders/bitmapFontParser.js https://github.com/pixijs/pixi.js/blob/dev/src/extras/BitmapText.js#L132 Also please look at https://github.com/PixelsCommander/pixi-sdf-text , its not BitmapText but it might suit your situation Quote Link to comment Share on other sites More sharing options...
MaskedPixel Posted March 21, 2017 Author Share Posted March 21, 2017 @ivan.popelyshev You are correct. I was exporting it using the Cocos2d/BMFont exporter in BMGlyph. The correct exporter is the Sparrow/Starling exporter. According to the loader documentation, it would take the fnt file. However, both the Cocos2d and Sparrow exporters use the fnt extension. ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 22, 2017 Share Posted March 22, 2017 Exactly. We're waiting for a champion who will solve that issue I will use your explanation whenever people ask for it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.