三峡大学土木水电学院肖泽云
本教程的主要目的是让你看完后,真正体会一下什么是XNA?XNA中主要包括哪些部分?相信你自己,在看完整个教程后,你也能设计自己的三维场景!祝你成功! 三、添加文字
[TextWindowsGame] 添加文字前需要先新建或添加一个
spritefont,是一个
XML文件。在解决方案资源管理器中
Content目录上点击右键选择“
Add”—“新建项…”,新建一个
spritefont,例如其名称为
SpriteFont1.spritefont。如下图所示。
1、打开
SpriteFont1.spritefont文件。
在<FontName>SpriteFont1</FontName>中间的SpriteFont1即为字体的名称,如更改为Arial。<Size>14</Size>中间的14位字体的大小,可以更改。
2、在Game1.cs文件中,首先全局定义:
SpriteFont myFont;
3、在LoadContent中添加:
myFont = Content.Load<SpriteFont>("SpriteFont1");
其中"SpriteFont1"即为
SpriteFont1.spritefont文件的
Asset name。
4、在
Draw函数中添加:
spriteBatch.DrawString(myFont, "Hello!Dream Xiao", new Vector2(100, 100), Color.GreenYellow);
其结果如下图所示:
整个程序的代码如下:
#region Using Statements//引用
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
#endregion
namespace TextWindowsGame
{
public class Game1 : Microsoft.Xna.Framework.Game //继承Game类
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
SpriteFont myFont;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()//初始化
{
base.Initialize();
}
protected override void LoadContent()//导入目录,每次游戏启动时都会启动
{
// 创建一个精灵,用于绘制图片
spriteBatch = new SpriteBatch(GraphicsDevice);
myFont = Content.Load<SpriteFont>("SpriteFont1");
}
protected override void UnloadContent()//卸载目录
{
// TODO: Unload any non ContentManager content here
}
protected override void Update(GameTime gameTime)/// 更新。用于检测碰撞、输入等
{
// 设置游戏结束事件
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
//添加更新的对象代码
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)//当绘制时被调用
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
// 添加绘图代码
spriteBatch.Begin();
spriteBatch.DrawString(myFont, "Hello!Dream Xiao", new Vector2(100, 100), Color.GreenYellow);
spriteBatch.End();
base.Draw(gameTime);
}
}
} <!--v:3.2-->
<!--E 文章--><!--S 翻页-->
分享到:
相关推荐
wp7 xna开发最强教程,让你最快的学习xna开发,能够写出一个小的游戏。
XWinForm(XNA2.0)——XNA虚拟WinForm窗体 XWinForm(XNA2.0)——XNA虚拟WinForm窗体 XWinForm(XNA2.0)——XNA虚拟WinForm窗体
XNA平台游戏开发中文教程,对于入门来说是不可多得的靓文.
xna游戏的开发介绍以及编程代码 是学习xna开发的必读之书
XNA开发简单教程,熟悉vs2010开发环境及XNA框架
是大学xna教材,这是入门级的,对于xna入门者来说,可以参阅的
XWinForm——XNA虚拟WinForm窗体 XWinForm——XNA虚拟WinForm窗体 XWinForm——XNA虚拟WinForm窗体 XWinForm——XNA虚拟WinForm窗体
Microsoft 的 XNA 游戏开发 资料。
国内第一本XNA教程中文《XNA入门指南》,经《A Beginners Guild to XNA》原作者 Mike Fleischauer 书面授权中国XNA开发网翻译!书中如有错误请访问www.ChinaXNA.com 或者 www.XNADev.cn
XNA Game Studio Express 是专业跨平台整合型游戏开发套件「XNA Studio」的简化版
基于XNA框架开发的连连看小游戏,使用C#语言
XNA中文教程(共四章,内含代码)XNA中文教程(共四章,内含代码)
此版是中文版,非常难得的资料,英文版是Professional XNA Game Programming For Xbox 360 and Windows。
Direct 3D与XNA游戏开发源码,很优秀的书,很优秀的源代码。
Xna游戏编辑器框架——WinForm内嵌Xna
Direct.3D和XNA游戏开发基础(C#语言版)
Direct 3D与XNA游戏开发光盘资源(6卷).part3
XNA游戏开发SDK安装包,安装后在Visual Studio中可以做XNA游戏项目
xna4.0教程,pdf文档,简单入门的教材,通俗易懂