SixLabors.Fonts.MonoGame
Add color parameter to SpriteBatch.DrawText
注意してください。これが、このリポジトリがアーカイブされる理由です。
.NET 6以降のMonogameのsixlabors.fontsの非公式ポート。
これはWindowsでのみテストされています。他のシステムで動作するはずですが、そうでない場合は、問題を開いてください。このライブラリも新しく、最適ではありません。プルリクエストは大歓迎です!
前提は単純です。 FontEngineがあり、フォントを保存するために使用します。次に、 FontEngineを使用してロードされたフォントを取得し、描画します。
// 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 ) ;おそらく、1つのフォントがあり、その名前を何度も繰り返し入力し続けたくありません。または、ゲームにはMODシステムがあり、MODは独自のフォントにロードして、ゲーム全体のデフォルトとして使用できます。そのため、デフォルトのフォント名を変更できます。
// 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 ) ;不足しているグリフの場合、sixlabors.fontsはフォールバックフォントを提供します。このライブラリもそれらを実装します。 FontEngineのFallbackFontFamiliesリストに追加すると、フォールバックフォントを追加できます。
// We are using the code from the above examples.
fontEngine . FallbackFontFamilies . Add ( font ) ; FontEngine ConstructorのaddSystemFonts TRUEに設定されている場合(これはデフォルトです)、フォントArial 、 Courier 、 Helveticaフォールバックフォントリストに追加されます。