Jump to content

Error when creating a BitmapText object.


MaskedPixel
 Share

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

@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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...