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字体中。