dotnet add package Unofficial.SixLabors.Fonts.MonoGame --version 1.1.0
NuGet\Install-Package Unofficial.SixLabors.Fonts.MonoGame -Version 1.1.0
<PackageReference Include="Unofficial.SixLabors.Fonts.MonoGame" Version="1.1.0" />
paket add Unofficial.SixLabors.Fonts.MonoGame --version 1.1.0
#r "nuget: Unofficial.SixLabors.Fonts.MonoGame, 1.1.0"
// Install Unofficial.SixLabors.Fonts.MonoGame as a Cake Addin #addin nuget:?package=Unofficial.SixLabors.Fonts.MonoGame&version=1.1.0 // Install Unofficial.SixLabors.Fonts.MonoGame as a Cake Tool #tool nuget:?package=Unofficial.SixLabors.Fonts.MonoGame&version=1.1.0
Unofficial port of SixLabors.Fonts to MonoGame for .NET 6 and above.
This has only been tested on Windows. It should work on other systems, but if it doesn't, please open an issue. This library is also new and unoptimised. Pull requests are welcome!
The premise is simple: we have a
FontEngine, which we use to store our fonts. We then use the
FontEngine to get a loaded font, and we draw with it.
// Load up our very epic fonts!!! FontEngine engine = new(); engine.LoadFont("path/to/some-cool-font.ttf"); // The font name from the truetype file is what we need to use here. MonoGameFont font = engine.GetFont("some-cool-font", 24f); // We've got the font! Now we can draw. // We have an extension method on SpriteBatch just for that. // It's in SixLabors.Fonts.MonoGame.Utils batch.DrawText(font, "Hello, world!", new Vector2(10, 10), Color.White);
Default font name
Presumably, you have one font and you don't want to keep typing its name over and over again. Or, maybe your game has a mod system, and mods can load in their own font and use it as the default for the entire game. In cases as such, you can modify the default font name.
// We are using the code from the above example. // We're setting the DefaultFontName to the font we'll be using engine.DefaultFontName = "some-cool-font"; // Now we can forget about the name at all! MonoGameFont defaultFont = engine.GetDefaultFont(24f);
For missing glyphs, SixLabors.Fonts provides fallback fonts. This library implements them as well.
You can add a fallback font by adding it to the FallbackFontFamilies list in
// We are using the code from the above examples. fontEngine.FallbackFontFamilies.Add(font);
addSystemFonts in the
FontEngine constructor is set to true (which is the default), the fonts
Helvetica will be added to the fallback fonts list.
|.NET||net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net6.0-windows7.0|
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
Added color parameter to SpriteBatch.DrawText