SixLabors.Fonts.MonoGame
Add color parameter to SpriteBatch.DrawText
請當心。這就是為什麼此存儲庫被存檔的原因。
六勞工組織的非官方港口。
這僅在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 ) ;據推測,您有一種字體,並且不想一遍又一遍地鍵入它的名稱。或者,也許您的遊戲具有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中的HallbackFontFonamilies列表中來添加後備字體。
// We are using the code from the above examples.
fontEngine . FallbackFontFamilies . Add ( font ) ;如果FontEngine構造函數中的addSystemFonts設置為true(默認為默認值),則將添加到Arial , Courier和Helvetica字體中。