Phaser v3.70 Font Test
Testing font rendering with Phaser 3
by Akurn
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/3.70.0/phaser.min.js"></script>
JavaScript
class Example extends Phaser.Scene {
preload () {
this.load.script('webfont', 'https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js')
}
create () {
let add = this.add
WebFont.load({
google: {
families: [ 'Andika' ]
},
active: function () {
add.text(10, 10, 'Here is some long text that should render with a custom font.', { fontFamily: 'Andika', fontSize: 14, color: '#ffffff' })
add.text(10, 40, 'Here is some longer and bigger text that should render with a custom font.\nAlso has a new line.', { fontFamily: 'Andika', fontSize: 20, color: '#ffffff' })
add.text(10, 100, 'Here is the largest text with a custom font.', { fontFamily: 'Andika', fontSize: 34, color: '#ffffff' })
}
})
}
}
const config = {
type: Phaser.AUTO,
width: 600,
height: 400,
parent: 'font-example',
scene: Example
};
const game = new Phaser.Game(config)