message.txt |
中文输入测试,日本語テストを入力する9 D% ] c( J1 a |
DefaultFontProcessor.cs |
using System.IO; using Microsoft.Xna.Framework.Content.Pipeline;6 P4 r: M3 v9 Z% F. Y using Microsoft.Xna.Framework.Content.Pipeline.Graphics; using Microsoft.Xna.Framework.Content.Pipeline.Processors; & J; d! R0 k5 l6 y" X6 L namespace FontProcessors# g6 m6 G0 K+ Q5 M { [ContentProcessor] public class DefaultFontProcessor : FontDescriptionProcessor8 K/ n/ L, ]$ g# f& Z( Y! ] {* a, h. z3 M5 r$ b! d public override SpriteFontContent Process(FontDescription input, ContentProcessorContext context)( f d' Y' x; y$ \2 Y- ~ { //载入文件 string fullPath = Path.GetFullPath("message.txt"); context.AddDependency(fullPath);( b2 ^+ m. ?: T: m, z+ q, K# M string letters = File.ReadAllText(fullPath, System.Text.Encoding.UTF8); # p* z, a0 Q: q' |4 i //导入字符 foreach (char c in letters) { input.Characters.Add(c);; q! A4 L2 H+ }& m }+ B6 u: K6 W* C% G return base.Process(input, context); } } } $ y7 s5 l: z0 f! z |
Game1.cs |
using System;) T( e) o6 d6 S3 c: g6 U( S using System.Collections.Generic; using Microsoft.Xna.Framework;" a8 }4 p' u# D9 f/ y- e using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content;3 ?" Y e( `0 l, {: O' t$ G5 i using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input;6 b% T1 q* w9 H: r0 n using Microsoft.Xna.Framework.Net; using Microsoft.Xna.Framework.Storage; 5 m F& y1 \% x8 r, O namespace HelloWorld {+ G1 I& q% x8 v# ]& S' k' l public class GameMain : Microsoft.Xna.Framework.Game { private GraphicsDeviceManager graphics; 1 H7 C4 R9 M9 g private SpriteBatch spriteBatch;7 U! L' f% Z% x& J0 r private SpriteFont font; c" b l( e: Q" x public GameMain() { graphics=new GraphicsDeviceManager(this); Content.RootDirectory="Content"; }+ C8 ]. a' f* } 0 n, g3 N) ~. Z7 o# ~ protected override void Initialize() { base.Initialize();, Y6 y9 J! H0 a* I }$ }+ |$ A# B% e6 o' y" p5 N protected override void LoadContent() { spriteBatch=new SpriteBatch(GraphicsDevice);- S( u* d; \8 a7 ]; w" h9 f font=Content.Load<SpriteFont>("DefaultFont"); } * D+ t) J& k0 x4 t" o0 @' R protected override void UnloadContent() {# [7 V. _4 Q8 ^ }9 j8 h+ ~* e/ K m( r * s/ I) C! D3 T2 M% K4 @ protected override void Update(GameTime gameTime) {! d+ C& ?5 C$ a: N9 U5 P if (GamePad.GetState(PlayerIndex.One).Buttons.Back== A6 c; O5 V# D: X$ J, d ButtonState.Pressed) { Exit(); }! U9 y8 J$ y& S% F1 P4 e base.Update(gameTime);% M* ~/ p$ S) Z& o. k+ g! u5 O } 4 M3 _3 T, C+ O6 I " C7 I+ ]1 }5 m. x7 P7 ], y, H protected override void Draw(GameTime gameTime) {$ q; E+ L! t+ @( ?4 b# [; ]9 i graphics.GraphicsDevice.Clear(Color.CornflowerBlue); ; ^ J j+ I: h spriteBatch.Begin();/ `( f! y. f' _+ Y) \! s DrawString("中文输入测试,日本語テストを入力する",50,50); spriteBatch.End();# j! d U% P9 z3 H" b - K- Q! c A, O& F ?: q . d/ L* ]/ G; R$ S2 j3 x9 m" a2 K; D base.Draw(gameTime);% G! F$ Z v2 V3 e/ r; U } ' `: |/ D# U; `$ Q0 O9 V 2 t9 e1 g" k; ]; t4 l9 p private void DrawString(String str,int x,int y) { spriteBatch.DrawString(font,str,new Vector2(x,y),Color.White);3 z9 u/ f- J3 A5 N5 G6 l }( r! G* M/ R5 x! l4 W } } |
欢迎光临 冒险解谜游戏中文网 ChinaAVG (https://chinaavg.com/) | Powered by Discuz! X3.2 |