Phaser-CE v2.20 Font Test

Testing font rendering with Phaser 2

by Akurn

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser-ce/2.20.0/phaser.min.js"></script>

JavaScript

let game = new Phaser.Game(600, 400, Phaser.CANVAS, 'font-example', { preload: preload, create: create })

function preload() {
  game.load.script('webfont', 'https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js')
}

function create() {
  WebFont.load({
    google: {
      families: [ 'Andika' ]
    },
    active: function () {
			let text1 = game.add.text(10, 10, 'Here is some long text that should render with a custom font.', { font: 'Andika', fontSize: 14, fill: '#ffffff' })
			let text2 = game.add.text(10, 40, 'Here is some longer and bigger text that should render with a custom font.\nAlso has a new line.', { font: 'Andika', fontSize: 20, fill: '#ffffff' })
			let text3 = game.add.text(10, 100, 'Here is the largest text with a custom font.', { font: 'Andika', fontSize: 34, fill: '#ffffff' })
      
      // to fix Windows font rendering issues
      // text1.updateText()
      // text2.updateText()
      // text3.updateText()
    }
  })
}