zoukankan      html  css  js  c++  java
  • 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)
  • 相关阅读:
    [分享]一个天气预报的WebService应用实例
    XMLHttpRequest Ajax 实例简介
    CSS选择符
    MSDN SmartCast更改下载步骤
    发掘VS2005 SP1 (二) 更好的支持主题
    .Net+MySQL组合开发(二) 数据访问篇
    最近一打开cnblogs首页,就弹出电影网站!
    今天有点爽
    .Net+MySQL组合开发(三) 乱码篇
    发掘VS2005 SP1 (三) 母模页
  • 原文地址:https://www.cnblogs.com/XiaoLang0/p/12930692.html
Copyright © 2011-2022 走看看