[Phaser 3] Font Loader Plugin

https://github.com/Qugurun/Phaser3-Font-Loader-Plugin

This plugin enhances Phaser 3 functionality by providing support for loading font files. It allows seamless integration of custom fonts in games or applications developed using Phaser 3. The plugin empowers developers to easily track the loading process of font files, ensuring efficient handling of font assets similar to how Phaser manages other supported file types.

import 'phaser';
import { FontLoaderPlugin } from './plugin/font_loader_plugin.js';

const config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    scene: {
        preload: preload,
        create: create
    },
    plugins: {
        global: [{
            key: 'FontLoaderPlugin',
            plugin: FontLoaderPlugin,
            start: true
        }]
    }
};

const game = new Phaser.Game(config);

function preload() {
  this.load.font('baloo', 'assets/font/baloo.ttf');
}

function create() {
    this.add.text(100, 100, 'Hello Phaser 3 with custom font!', { fontFamily: 'baloo', fontSize: '32px', color: '#ffffff' });
}

Test:

preload(){
  this.load.on("fileprogress", function (file) {
    console.dir(file)
  });

  this.load.on('complete', function () {
    console.log('Complete!');
  });

  for (let index = 0; index < 5000; index++) {
    this.load.font("baloo"+index, "assets/font/baloo.ttf"); 
  }
}
3 Likes