
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
phaser3-bitmapfont-factory
Advanced tools
Creates bitmapfonts in Phaser3 at runtime, using available browser fonts
This typescript class creates bitmapfonts at runtime ready to use in a Phaser3 game, using default or already loaded browser fonts.
Try demo here: https://jjcapellan.github.io/phaser3-bitmapfont-factory/
There are two alternatives:
<script src = "bmff.umd.js"></script>
<script src = "https://cdn.jsdelivr.net/gh/jjcapellan/phaser3-bitmapfont-factory@2.2.0/dist/bmff.umd.js"></script>
Important: the class is exposed as BMFFactory
npm i phaser3-bitmapfont-factory
Then you can acces the class as:
const BMFFactory = require('phaser3-bitmapfont-factory/dist/bmff');
// In scene.create function
const bmff = new BMFFactory(this, onComplete);
import BMFFactory from 'phaser3-bitmapfont-factory';
// In scene.create function
const bmff = new BMFFactory(this, onComplete);
There are three steps:
// In scene.create function
let bmff = new BMFFactory(this, () => {
// your code here.
// this code is executed when bitmapfonts are ready
// i.e.: this.scene.start('nextScene');
});
BMFFactory(scene, onComplete, options)
Parameters:
// inside your Phaser.create() function...
// What glyphs do you want to use?
const chars = ' 0123456789abcdefghijklmnopqrstuwxyz,.';
// This adds as task the creation of a bitmapfont using "Arial" font family and calculating its kernings
bmff.make('key1', 'Arial', chars, { fontSize: '64px', color: '#555568' });
// We can use fallback fonts like in css
bmff.make('key2', ['Lato', 'Lucida Grande', 'Tahoma', 'Sans-Serif'], chars, { fontSize: '64px', color: '#555568' });
// BMFFactory has three predefined arrays of common web-safe and browser default fonts:
// bmff.defaultFonts.sansSerif
// bmff.defaultFonts.sans
// bmff.defaultFonts.monospace
// In this case I'm using a monospace font so I don't need kernings
bmff.make('key3', bmff.defaultFonts.monospace, chars, { fontSize: '64px', color: '#555568' }, false);
make(key, fontFamily, chars, style, getKernings)
The method make creates a task to make a bitmapfont, and adds it to the queue.
Parameters:
this.add.bitmapText(x, y, key, 'text')).// This function must be called after adding all tasks
bmff.exec();
exec()
This asynchronous method executes all tasks previously added to the task queue. When finished, it calls onComplete callback.
This example shows the generation and use of one bitmapfont in the same scene.
Sometimes we need to generate several bitmapfonts with many glyphs. For these cases is better generate the bitmapfonts previously in a load scene (look the demo folder of this repository).
import Bmff from "phaser3-bitmapfont-factory";
class Game extends Phaser.Scene {
constructor() {
super("game");
}
create() {
const bmff = new Bmff(this,
() => {
// Now bitmapfonts are ready
this.add.bitmapText(320, 180 - 3 * 42, 'fallback', 'my defined fallback font')
.setOrigin(0.5);
this.add.bitmapText(320, 180 - 42, 'defserif', 'default serif font')
.setOrigin(0.5);
let b = this.add.bitmapText(320, 180 + 42, 'defmono', 'default monospace font')
.setOrigin(0.5);console.log(b);
});
const chars = " abcdefghijklmnopqrstuvwxyz";
const config1 = { fontSize: '42px', color: '#1a1c2c'};
const config2 = { fontSize: '42px', color: '#1a1c2c', fontStyle: 'italic' };
const config3 = { fontSize: '42px', color: '#1a1c2c', fontStyle: 'bold' };
bmff.make('defmono', bmff.defaultFonts.monospace, chars, config1, false);
bmff.make('defserif', bmff.defaultFonts.serif, chars, config2);
bmff.make('fallback', ['fdgsfd', 'Arial'], chars, config3);
bmff.exec();
}
}
function runGame() {
let config = {
type: Phaser.AUTO,
width: 640,
height: 360,
parent: "game",
backgroundColor: '#cdcdcd',
scene: [Game],
};
new Phaser.Game(config);
}
window.onload = function () {
runGame();
};
Phaser3 Bitmapfont Factory is licensed under the terms of the MIT open source license.
FAQs
Creates bitmapfonts in Phaser3 at runtime, using available browser fonts
The npm package phaser3-bitmapfont-factory receives a total of 179 weekly downloads. As such, phaser3-bitmapfont-factory popularity was classified as not popular.
We found that phaser3-bitmapfont-factory demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.