من فضلك احذر. هذا هو السبب في أن هذا الريبو أرشفة.
منفذ غير رسمي لـ Sixlabors.fonts to monogame لـ .NET 6 وما فوق.
تم اختبار هذا فقط على 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 ، ويمكن أن يتم تحميل MODS بخطها الخاص واستخدامه كإعداد افتراضي للعبة بأكملها. في الحالات على هذا النحو ، يمكنك تعديل اسم الخط الافتراضي.
// 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 خطوط احتياطية. هذه المكتبة تنفذهم كذلك. يمكنك إضافة خط احتياطي عن طريق إضافته إلى قائمة FackFontFamilies في FontEngine .
// We are using the code from the above examples.
fontEngine . FallbackFontFamilies . Add ( font ) ; إذا تم ضبط addSystemFonts في مُنشئ FontEngine على True (وهو الافتراضي) ، فسيتم إضافة الخطوط Arial و Courier و Helvetica إلى قائمة الخطوط المتوقفة.