Skip to content
Snippets Groups Projects
Commit ad0fc02e authored by Paolo Brasolin's avatar Paolo Brasolin
Browse files

feat: #fe webfont preloading

parent 0cf9639a
No related branches found
No related tags found
No related merge requests found
...@@ -5,13 +5,31 @@ import { ...@@ -5,13 +5,31 @@ import {
SoundEffects, SoundEffects,
SpriteSheets, SpriteSheets,
} from "./assets"; } from "./assets";
const RexWebFontLoaderPluginFileConfig: Phaser.Types.Loader.FileConfig = {
type: "plugin",
key: "rexwebfontloaderplugin",
url: "https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rexwebfontloaderplugin.min.js",
// start: true,
};
const WebFonts = {
google: {
families: ["UnifrakturMaguntia", "Cousine"],
},
};
export default class LoadingScene extends Phaser.Scene { export default class LoadingScene extends Phaser.Scene {
progressBar!: Phaser.GameObjects.Graphics; progressBar!: Phaser.GameObjects.Graphics;
progressBox!: Phaser.GameObjects.Graphics; progressBox!: Phaser.GameObjects.Graphics;
progressTxt!: Phaser.GameObjects.Text; progressTxt!: Phaser.GameObjects.Text;
constructor() { constructor() {
super("preload"); super({
key: "preload",
// NOTE: this plugin is loaded in the pack (instead of the preload) because we need to use it in the preload
pack: { files: [RexWebFontLoaderPluginFileConfig] },
});
} }
preload() { preload() {
...@@ -27,6 +45,11 @@ export default class LoadingScene extends Phaser.Scene { ...@@ -27,6 +45,11 @@ export default class LoadingScene extends Phaser.Scene {
this.load.on("fileprogress", this.onLoadFileProgress.bind(this)); this.load.on("fileprogress", this.onLoadFileProgress.bind(this));
this.load.on("complete", this.onLoadComplete.bind(this)); this.load.on("complete", this.onLoadComplete.bind(this));
// @ts-expect-error TODO: addToScene exists but it's private; find a kosher alternative.
this.plugins.get("rexwebfontloaderplugin").addToScene(this);
// @ts-expect-error the plugin is loaded but the LoaderPlugin signature isn't extended
this.load.rexWebFont(WebFonts);
this.load.image(BackgroundImages); this.load.image(BackgroundImages);
this.load.spritesheet(SpriteSheets); this.load.spritesheet(SpriteSheets);
this.load.audio(SoundEffects); this.load.audio(SoundEffects);
...@@ -58,7 +81,7 @@ export default class LoadingScene extends Phaser.Scene { ...@@ -58,7 +81,7 @@ export default class LoadingScene extends Phaser.Scene {
origin: 0.5, origin: 0.5,
text: "LOADING: 0%", text: "LOADING: 0%",
style: { style: {
fontFamily: "Courier", fontFamily: "monospace, Cousine",
fontStyle: "bold", fontStyle: "bold",
fontSize: "32px", fontSize: "32px",
color: "white", color: "white",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment