I try to load a custom font into Pixi.js (2D WebGL framework).
They have an example using .woff google fonts:
https://github.com/GoodBoyDigital/pixi.js/tree/master/examples/example%2010%20-%20Text
I converted my .ttf to .woff and added in css:
@font-face
{
font-family: "HU_Adrien";
src: local('HU_Adrien'), url('HU_A0046.woff') format('woff');;
}
div.font{
font-family: "HU_Adrien";
color: white;
}
It shows in my div but not in my Pixi stage.
...
// create a text object with a nice stroke
var spinningText = new PIXI.Text("I'm fun!", {font: "160px HU_Adrien", fill: "#cc00ff", align: "center", stroke: "#FFFFFF", strokeThickness: 6});
// setting the anchor point to 0.5 will center align the text... great for spinning!
spinningText.anchor.x = spinningText.anchor.y = 0.5;
spinningText.position.x = 620 / 2;
spinningText.position.y = 400 / 2;
...
You need to convert HU_A0046.woff
with this tool to HU_A0046.XML
and add the file name to the preload list. Then you should call PIXI.Bitmaptext
Example:
...
var loader = new PIXI.AssetLoader(/*more media...*/, ["HU_A0046.xml"]);
var spinningText = new PIXI.BitmapText("I'm fun!", { font: "35px FontName"}); //You can see the font name within the XML
spinningText.position.x = 620 / 2;
spinningText.position.y = 400 / 2;
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With