use*_*254 12 javascript webgl pixi.js
我尝试将自定义字体加载到Pixi.js(2D WebGL框架)中.
他们有一个使用.woff谷歌字体的例子:
https://github.com/GoodBoyDigital/pixi.js/tree/master/examples/example%2010%20-%20Text
我将.ttf转换为.woff并添加到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;
}
Run Code Online (Sandbox Code Playgroud)
它显示在我的div中但不在我的Pixi阶段.
...
// 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;
...
Run Code Online (Sandbox Code Playgroud)
您需要将HU_A0046.woff与http://www.angelcode.com/products/bmfont/工具转换为HU_A0046.XML格式,然后将文件名添加到预加载列表中.然后你应该调用PIXI.Bitmaptext
例:
...
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;
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7148 次 |
| 最近记录: |