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;
...
It worked in my pixi 4 app after installing the .woff file (no conversion or bitmap text required) and adding
to my pixi style definition.
fonts.css
app.js
webpack.config.js
Make sure to install
You need to convert HU_A0046.woff with http://www.angelcode.com/products/bmfont/ tool to HU_A0046.XML format and then add the file name to the preload list. Then you should call PIXI.Bitmaptext
Example:
In order to use a custom web font with PIXI you need to use the google web font api with it you can use web fonts from Google and other cdns as well as your own local web fonts you can read more at https://github.com/typekit/webfontloader
In this example, the fonts.css file might look something like this:
*it's important to start using the font after they are rendered
*convert your font with a tool like: http://www.font2web.com/
*it will give you the needed web font files as well as the css code for your custom fonts