• XNA平面字体


    1.字体的初始化类:

     1 using Microsoft.Xna.Framework;
     2 using Microsoft.Xna.Framework.Graphics;
     3 using System;
     4 using System.Linq;
     5 
     6 namespace xiaolang
     7 {
     8     public class Font
     9     {
    10         XNADeviceService graphicsDeviceService;
    11 
    12         ServiceContainer services = new ServiceContainer();
    13 
    14         GraphicsDevice graphicsDevice;
    15 
    16         SpriteBatch spriteBatch; 
    17 
    18         SpriteFontX spriteFontX; 
    19 
    20         public Font(IntPtr mainHandle, GraphicsDevice GraphicsDevice)
    21         {
    22             graphicsDeviceService = XNADeviceService.AddRef(mainHandle, 1, 1);
    23             services.AddService<IGraphicsDeviceService>(graphicsDeviceService);
    24 
    25             graphicsDevice = GraphicsDevice; 
    26 
    27             //设定字体,样式,大小
    28             spriteBatch = new SpriteBatch(graphicsDevice);
    29             spriteFontX = new SpriteFontX(new System.Drawing.Font("宋体", 12f),
    30                 this.graphicsDeviceService, System.Drawing.Text.TextRenderingHint.SingleBitPerPixel);
    31         }   
    32         public void DrawFont(Vector2 center_V2 , string str_font)
    33         {  
    34             //字体
    35             graphicsDevice.DepthStencilState = DepthStencilState.None;
    36 
    37             spriteBatch.Begin();
    38 
    39             spriteBatch.DrawStringX(spriteFontX, str_font, center_V2, Color.Red);
    40 
    41             spriteBatch.End();
    42 
    43             graphicsDevice.DepthStencilState = DepthStencilState.Default;
    44         } 
    45     }
    46 }    

    2.初始化类的简单调用:

     1 using Microsoft.Xna.Framework;
     2 using Microsoft.Xna.Framework.Graphics;
     3 using System; 
     4  
     5 namespace xiaolang
     6 {
     7     public class WriteFont
     8     { 
     9         public Font font;
    10  
    11         public bool B_Thread = true;  
    12  
    13         public WriteFont()
    14         {
    15              font= new Font(this.Handle, GraphicsDevice);
    16 
    17              Thread TFont= new Thread(new ThreadStart(Thread_Font));
    18              TFont.Start(); 
    19         }  
    20         private void Thread_Font()
    21         {
    22             while (B_Thread)
    23             {
    24                 font.DrawLable(new Vector2(200,200),"好人一生平安... ..."); 
    25                 Thread.Sleep(50);
    26             }
    27         } 
    28     }
    29 }

    3.字体资源:

    链接:https://pan.baidu.com/s/1rgonhi0VZ95LAl4CcarkAg
    提取码:2ot1

    支持个人观看使用,如商用或转载,请告知! -----萧朗(QQ:453929789 Email:xiaolang_xl@sina.com)
  • 相关阅读:
    优酷kux转mp4
    C++实现将一个文件夹内容拷贝至另一个文件夹
    获取NX一组属性
    获取NX特征名称(无时间戳)
    利用glog打印日志
    C++获取运行程序当前目录
    获取NX装配结构信息
    解析形如(k,v)(k,v)(k,v)字符串
    多NX如何共存
    C++ (C#)实现获取NX PART预览图
  • 原文地址:https://www.cnblogs.com/XiaoLang0/p/12930692.html
Copyright © 2020-2023  润新知