Jump to content

BitmapText/BitmapFont


JakeMN
 Share

Recommended Posts

been working at this for a bit using other examples as basis. have arrived at a place where i cannot get the font properly loaded, even though my check indicates that it's available. i have broken the code out a bit more than i normally would for ease of debugging.

 

please note that  createTextFields() is called from window.onload. i do not get "Font not loaded" printed to console

 

	function createTextFields(){     
            const loader = new PIXI.Loader();

            loader.add('Arial_0', 'fonts/Arial_0.fnt');
            loader.load(onFontLoaded);
        }


        function onFontLoaded(){
            if (!PIXI.BitmapFont.available['Arial_0']) 
              console.log("Font not loaded");   
            else
               createText();
        }

        function createText() {
            let bitmapText = new PIXI.BitmapText("text using a fancy font!", {font: "Arial_0", align: "right"});
            bitmapText.anchor.set(0.5)
            bitmapText.position.x = window.innerWidth / 2
            bitmapText.position.y = window.innerHeight / 2
            backgroundSprite.addChild(bitmapText)
        }

 

 

the error i get is posted below:

 

pixi.js:38404 Uncaught Error: Missing BitmapFont "undefined"
    at new BitmapText (pixi.js:38404)
    at createText (index.html:117)
    at onFontLoaded (index.html:113)
    at MiniSignal.dispatch (pixi.js:24690)
    at Loader._onComplete (pixi.js:26997)
    at pixi.js:27035
    at next (pixi.js:24811)
    at Loader.SpritesheetLoader.use (pixi.js:36237)
    at pixi.js:27018
    at pixi.js:24819

 

the .fnt and .png are attached, and were created using bmfont., any help would be greatly appreciated. thanks 

 

 

Arial_0.png

Arial_0.fnt

Link to comment
Share on other sites

for completion, here is the corrected script that works with the attached font. you would need to make sure backgroundSprite is changed to a sprite in your scene. 

	function createTextFields(){     
            const loader = new PIXI.Loader();

            loader.add('Arial_0', 'fonts/Arial_0.fnt');
            loader.load(onFontLoaded);
        }


        function onFontLoaded(){
            if (!PIXI.BitmapFont.available['Arial_0']) 
              console.log("Font not loaded");   
            else
               createText();
        }

        function createText() {
            let bitmapText = new PIXI.BitmapText("text using a fancy font!", {fontName: "Arial_0", align: "right"});
            bitmapText.anchor.set(0.5)
            bitmapText.position.x = window.innerWidth / 2
            bitmapText.position.y = window.innerHeight / 2
            backgroundSprite.addChild(bitmapText)
        }

 

Edited by JakeMN
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...