message.txt |
中文输入测试,日本語テストを入力する, f7 t3 k: r! J9 @, Z ] |
DefaultFontProcessor.cs |
using System.IO; using Microsoft.Xna.Framework.Content.Pipeline; using Microsoft.Xna.Framework.Content.Pipeline.Graphics;1 `7 A' s- Y" _$ G) C using Microsoft.Xna.Framework.Content.Pipeline.Processors;8 z) q$ A2 Q8 ~1 F- _4 ^4 i6 q 9 w) u* ?! v. _ namespace FontProcessors1 h" q6 y( b0 ]4 C" r B {1 l# S) ]8 I5 [. y7 a [ContentProcessor] public class DefaultFontProcessor : FontDescriptionProcessor+ w! O- Z! Q2 Q8 @$ O; W {# K L, z" Z3 N' g6 f' [! m2 k public override SpriteFontContent Process(FontDescription input, ContentProcessorContext context)% F, W- K% E# @- a8 t8 \ {3 q. {. q- W* z- u; f# M0 D; v. N4 T //载入文件 string fullPath = Path.GetFullPath("message.txt"); context.AddDependency(fullPath); string letters = File.ReadAllText(fullPath, System.Text.Encoding.UTF8);+ M8 I% }1 s) Y, q ( Z+ h8 c) B( @2 }4 m / H3 a* S( E% \: K5 u4 N7 n //导入字符 foreach (char c in letters)$ m. f0 v7 M# {. Q8 e' f {- F! Z0 B3 q9 f8 }2 ?8 G8 d input.Characters.Add(c);8 `" D- h3 z8 f6 N0 c: P }9 e6 O7 [' x. [+ ~ return base.Process(input, context); } }# N) g; q; P: C3 @ }4 K3 N) Z7 Y# z+ d/ m, Y: N* G( ~ ; l3 D5 N: a9 \! ~2 f, E4 S: O |
Game1.cs |
using System;, q9 a* S; O% x5 b3 V using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio;& l l' q; _# A using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics;, {! ~% ~! j1 e using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Net;) j7 m' N! f! L) c: G6 C q using Microsoft.Xna.Framework.Storage; namespace HelloWorld { public class GameMain : Microsoft.Xna.Framework.Game { private GraphicsDeviceManager graphics; private SpriteBatch spriteBatch; private SpriteFont font; & G9 E; d! R4 d2 V public GameMain() {! ^) Q/ j' ] v0 N3 y" x graphics=new GraphicsDeviceManager(this); Content.RootDirectory="Content"; } 8 h+ f0 [% D4 ^) @7 j6 ~& Q. [ 7 b4 U8 E! T4 m% x( q3 N protected override void Initialize() { base.Initialize(); } ) T# J: _! `' x M9 m% l) c protected override void LoadContent() {7 g/ y+ o* A# i3 s; S spriteBatch=new SpriteBatch(GraphicsDevice);& F3 G' x- b! N font=Content.Load<SpriteFont>("DefaultFont");! q. n F% M! _ } 8 f# v6 `: F# [+ ]3 G- K protected override void UnloadContent() {) M: A u' \6 H ?' v. @ }; }6 f9 H5 X( g( B. n 9 R* R5 C7 m, i, G( B+ { protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back== ButtonState.Pressed) { Exit();5 s+ q7 l' T- W }" A' g0 y' ^' @3 f7 \1 G 0 `9 V& d% @# Q+ c# y: O1 C base.Update(gameTime); } protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); , l- B3 n; \# D* _" ~* ? spriteBatch.Begin();1 i" F* N) m/ W) y2 ~ DrawString("中文输入测试,日本語テストを入力する",50,50); spriteBatch.End();+ @4 O' @, X, M) v3 I' a 4 U# \. G. p3 N: U3 t ) {3 |6 l6 }4 R* a base.Draw(gameTime); } 7 c! t# y0 a i l3 U private void DrawString(String str,int x,int y) { spriteBatch.DrawString(font,str,new Vector2(x,y),Color.White);2 ^8 K/ R. H5 U- [5 f- k } } }- P# {. X2 ?4 m! z, B3 @ |
欢迎光临 冒险解谜游戏中文网 ChinaAVG (https://chinaavg.com/) | Powered by Discuz! X3.2 |