2013-09-25 12 views
12

Provo a caricare un carattere personalizzato in Pixi.js (framework WebGL 2D).Carattere personalizzato in Pixi.js

Hanno un esempio utilizzando .woff google font:

https://github.com/GoodBoyDigital/pixi.js/tree/master/examples/example%2010%20-%20Text

ho convertito la mia Ttf a .woff e ha aggiunto 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; 
} 

si vede nel mio div ma non nel mio stadio di 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; 
... 
+0

Potrebbe non avere la sorgente elencata nella riga? Come il '.woff'? – Brendan

+2

Nell'esempio di GoodBoy stanno pre-caricando il font, non sono sicuro che tu abbia un problema di razza con css. prova a impostare '{font:" 160px HU_Adrien, arial "..." e vedi se hai almeno un testo. –

risposta

6

è necessario convertire HU_A0046.woff con http://www.angelcode.com/products/bmfont/ strumento per formato HU_A0046.XML e quindi aggiungere il nome del file alla lista precarico. Poi si dovrebbe chiamare PIXI.Bitmaptext

Esempio:

... 
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; 
... 
2

Per poter utilizzare un font Web personalizzata con PIXI è necessario utilizzare l'API web di Google carattere con esso è possibile utilizzare font Web da Google e altri CDN, nonché i propri font web locali si può leggere di più a https://github.com/typekit/webfontloader

<script> 
    WebFontConfig = { 
    typekit: { id: 'xxxxxx' }, 
    google: { 
     families: ['Droid Sans', 'Droid Serif'] 
    }, 
    custom: { 
     families: ['My Font', 'My Other Font:n4,i4,n7'], 
     urls: ['/fonts.css'] 
    }, 

    active: function() { 
     // do something 
     init(); 
    } 
    }, 

    active: function() { 
    // do something 
    init(); 
    } 
    }; 

    (function() { 
    var wf = document.createElement('script'); 
    wf.src = ('https:' == document.location.protocol ? 'https' : 'http') + 
       '://ajax.googleapis.com/ajax/libs/webfont/1.5.6/webfont.js'; 
    wf.type = 'text/javascript'; 
    wf.async = 'true'; 
    var s = document.getElementsByTagName('script')[0]; 
    s.parentNode.insertBefore(wf, s); 
    })(); 
</script> 

In questo esempio, il file potrebbe essere fonts.css Somet Hing come questo:

@font-face { 
    font-family: 'My Font'; 
    src: ...; 
} 
@font-face { 
    font-family: 'My Other Font'; 
    font-style: normal; 
    font-weight: normal; /* or 400 */ 
    src: ...; 
} 
@font-face { 
    font-family: 'My Other Font'; 
    font-style: italic; 
    font-weight: normal; /* or 400 */ 
    src: ...; 
} 
@font-face { 
    font-family: 'My Other Font'; 
    font-style: normal; 
    font-weight: bold; /* or 700 */ 
    src: ...; 
} 

* è importante per iniziare a utilizzare il tipo di carattere dopo che sono stati resi

* convertire il vostro carattere con uno strumento come: http://www.font2web.com/

* vi darà il tipo di carattere web necessaria file e il codice css css per i caratteri personalizzati

Problemi correlati