上星期我们发布了XNA Game Studio Express,以使学生和爱好者可以在Windows和Xbox360两个平台上用C#开发游戏。XNA Framework是一系列帮助开发人员编写游戏的类库。在beta版即将到来之际我想来花点时间通过对XNA 的三个关键点的解释来说明一下XNA Framework,也就是:XNA Framework的目标是什么,XNA Framework是什么,还有它可以做什么
目标
在开发的时候我们想到的是实现两个主要目的:
实现跨平台开发
XNA Framework的一个关键目标是实现游戏在Windows和Xbox 360分别运行的简易性,以让你可以先在Windows上开发一个游戏,然后简单的移植到Xbox360上去。我们的目标是提供一系列可以涵盖大约95%功能的跨平台APIs。这里要说的是由于某些原因两个环境间仍会有部分的不同,例如有些操作可能只在一个平台上有效。我估计大部分你开发的游戏是100%跨平台的。
制作游戏是一项有难度的工作。从学生和爱好者想要成为专业游戏开发人员更加困难。常常要在如何实现绘图,输入,运动等地方反复试验而浪费大量的时间和代码。XNA Framework的另一个目的就是使这一切变得容易起来。当我们在进行内部讨论的时候,我们经常提到开发体验的“头五分钟”。我们的想法是使你可以在头五分钟内开始编写你的游戏。你不必要考虑创建窗口,消息事件队列的弹出和处理,你不需要给出图片处理程序甚至掌握显示模式。你不需要创建一个图形设备然后在窗口重新定义大小和最小化的时候管理它。XNA Framework替你处理了这一切。你要做的第一件事就是为你的游戏逻辑写代码。
另一个问题是处理特定的游戏内容(Content),把一个内容导入到你的游戏中然后使它在运行时为你所用。XNA Framework的一项特性叫做内容管道(Content Pipeline)。通过它你可以极为简单的把一个内容引入你的游戏。关于这点将会在以后的文章作进一步的说明。不过想象一下,以后你可以像管理代码一样,将游戏的内容作为项目的一部分进行处理。内容管道将会为你处理内容的导入,编译和载入。
实现“头五分钟”的另一个方面在于我们将会提供一些Start Kits,这些Start Kits将会作为一个项目模版包含完整的游戏操作,以及源代码和媒体文件。在新建项目对话框中你可以使用它们,并在上面进行修改。最终你将可以直接打开一个在编写中的游戏,进行改写和调整之后,按下F5就可以马上得到反馈。每一个Start Kits都会有完整的说明文档,还包含一些指导教你如何修改增加游戏的特性。
未来的版本中游戏开发进程的简化还将得到不断改进。而我们总的努力方向就在于不断地降低游戏开发的门槛,使更多的人进入到游戏开发者的行列中来。
层(Layers)
在描述XNA Framework组成的时候,我们可以认为是一系列层次关系。
平台(Platform)
平台是XNA Framework的最下一层。它由一系列底层的原生代码和托管APIs组成。在这一层中有些APIs就是Direct3D 9, XACT, XInput和XContent.
核心框架(Core Framework)
核心框架是第一层,并且提供核心操作用来给其它层的进行扩展。如果你想要在直接使用托管DirectX,就应该是在这一层。在这一层次中包含了对图像,声音,输入和数据存储的处理。当我们要改进XNA Framwork,附加新的功能我们就要增建这一层。
扩展框架(Extended Framework)
扩展框架主要致力于游戏开发的简化。当前这一层有两个主要的部分:应用模块(Application Model)和内容管道。我们将通过这一层使你可以更容易的开发游戏,同时便于扩展。
游戏
游戏部分是最高的层次。这一层包含你的游戏逻辑代码和内容。在这一层将你的游戏逻辑和内容相整合。Start Kits、游戏模版和游戏内容部件就属于这一层。
特性
以上我们谈论了许多关于XNA Framework的目标以及它所划分的功能层次。但什么是XNA呢,让我们来看看。
应用模块(Application Model)
应用模块的意图在于抽象你的游戏所运行的平台,让你专注于游戏的编写。你不必关心创建窗口,管理消息队列,创建定时器或时钟和处理窗口消息。我们全都替你进行了封装。我们也提供一个GraphicsComponent(译注:图形组件,是一个类)以极为简单的方法对要绘图的图形设备进行创建和管理。在Xbox360上是不需要窗口和窗口消息的,这和Windows有很大不同,你也不必担心,因为在应用模块上两个平台是完全相同的。我们也提供通用模块让你简单的和其它人在游戏中合并GraphicsComponent,通过这样可以快速的建立可重用模块。GameComponents (译注:游戏组件集合,也是一个类)在你的游戏中可以由别人所写入。这样的处理在建立和快速运行或实现一个可重用的库的时候是很重要的。这一部分是我亲眼看着完善起来的,我相信我们将看到用户通过它实现许多神奇的东西。
图像处理
我们的图像APIs是基于Direct3D 9 APIs的。它们非常类似于MDX类型结构,但是经过了精心的重构和清理使它更容易使用,并且和.Net的设计方针保存一致。这部分和MDX最大的不同的在于,我们决定取消固定函数式(fixed-function)的管理方式,而使用一种全渲染驱动可编程管道(all shader-driven programmable pipeline)
我们这样做是有原因的。首先,可编程管道是实时计算机图形的未来。Direct3D 10和Xbox360都不再为固定函数提供支持。当我们和一些早期的合作者和客户讨论这些问题的时候,我们还是多少有点惊讶,其实他们对于跨平台的关注大于对原固定函数的关注。由于害怕在Windows中用固定函数APIs开发的程序(也许开发人员都不确切知道),在移植到Xbox360上时立刻得到大量的编译错误。当知道你的代码在一开始就可以确实的跨平台运行,这实在是令人放心不少。
我们还发现掌握渲染和特效是游戏编写中要迈出的一大步。所以我们尝试在托管DirectX 1.1 到 XNA Framework (Beta 1)中提供了一些移植向导式的API。例如BasicEffect类可以简单的通过设置属性,包含光照、纹理等等就可以在“五分钟”内实现对一个物体的呈现。使用BasicEffect而不需要直接去编写渲染,就可以很快地在屏幕上显示出一些东西。然后当你开始对渲染和特效较为熟悉,或者可以扩展类BasicEffect的呈现功能时,你也可以直接用它们来写你自己的渲染和特效。
声音处理
我们的声音APIs是建立在Windows和Xbox360通用的声音API——XACT上的。XACT的理念和Direct3D的渲染部分类似。声音的制作人员使用XACT的工具创建好声音效果包(packages),并且配置好音量,重复次数,声道混音(支持5.1)等等。开发人员得到这样的包之后再载入它,然后就可以简单的通过包的名字来调用声音,而无须考虑缓存,流导入等其它管理细节。例如音效人员制作了一个包含几个wav文件,有LFE效果并且和其它通道混音的声音包“BigExplosion”。而程序员不需要知道这方面的细节,他只要得到“BigExplosion”,然后对它调用Play。漂亮!简洁!
输入处理
输入API建立在基于一般Xbox360的控制器(译注:就是手柄)的XInput API之上,它也是跨平台的。输入提供一个立即模式(immediate mode)API而不需要初始化。不需要考虑获得或释放设备,设置共享模式等等。你只需在恰当的控制器类型上调用GetState就行了。我们提供了一个GamePad类型用来表示Windows和Xbox360上的Xbox360控制器。同时在Windows中还有键盘类型和鼠标类型。
存储处理
存储API提供了以平台无关方法来读取和保存游戏数据(例如保存游戏状态,高分值等等)的途径。在Windows中这不是什么问题,因为你可以使用System.IO。并且你可以通过环境(Environment)方法正确的为当前用户定位到存储的数据。在Xbox360上你需要使用Profile和存储设备来操作游戏状态,例如硬盘和记忆卡。XNA Framework的存储处理部分使这些变得很容易,并可以达到跨平台的效果。我们在Windows上对Xbox360这些操作进行了模拟,以使你用完全一样的代码在两个平台上读取和写入数据。
数学逻辑部分
数学API提供了一些游戏中常用的数学类型,例如Vector2, Vector3, Vector4, Matrix, Plane,还有 Ray。我们也提供了一些卷绑定(bounding volume)类型例如BoundingBox, BoundingSphere 和 BoundingFrustum。我们的绑定类型也包含交集和容积(containment)测试的方法。需要注意的是我们的数学库默认是右序的。这里我指的是在Matrix(矩阵)上的情况。例如我们只提供了一个对矩阵右序查看的CreateLookAt 方法,而不是分别提供CreateLookAtLH 和 CreateLookAtRH。我们这样设计的目的在于使其它外部内容和中间件的整合都较为统一而容易。如果大家都遵守这个约定那么按照这样开发的XNA Framework和外部的APIs就可以较容易的联合使用。以上我说的是默认的时候,进行左序操作是无需其它条件的。如果你确实需要使用左序(或者其它方法)操作也可以,你只需要自己写操作代码。
展望
目前我们注意力主要在刚发布到你手上的XNA Game Studio ExpressV1.0以及XNA Framework上。但是我们也在考虑未来版本的特性。如前面提过的为了添加新的功能操作,我们将对Core Framework层进行扩展。同时对Extended Framework进行增建,使得用XNA Game Studio Express创建游戏更容易。我们也会推出XNA Game Studio Professional,以使开发者可以用XNA Framework在Xbox360上开发商业游戏。请在下一个月中留意这方面的情况。
封装
我提到XNA Framework的一个目标在于让编写游戏更容易,使你专注于你的游戏而不是平台。它到底有多简单呢?下面的代码显示了一个可运行的XNA Framework游戏应用程序大体框架。
public
class SampleGame : Game
{
private GraphicsComponent graphics;
public SampleGame()
{
this.graphics =
new GraphicsComponent();
this.GameComponents.Add(graphics);
}
protected
override
void Update()
{
}
protected
override
void Draw()
{
this.graphics.GraphicsDevice.Clear(Color.Blue);
this.graphics.GraphicsDevice.Present();
}
static
void Main(string[] args)
{
using (SampleGame game =
new SampleGame())
{
game.Run();
}
}
}
public
class SampleGame : Game
{
private GraphicsComponent graphics;
public SampleGame()
{
this.graphics =
new GraphicsComponent();
this.GameComponents.Add(graphics);
}
protected
override
void Update()
{
}
protected
override
void Draw()
{
this.graphics.GraphicsDevice.Clear(Color.Blue);
this.graphics.GraphicsDevice.Present();
}
static
void Main(string[] args)
{
using (SampleGame game =
new SampleGame())
{
game.Run();
}
}
}
感谢你花时间阅读这篇文章。我希望我已经讲明白了XNA Framework到底提供什么。Beta版将会在几天内放出,所以欢迎您下载下来使用。然后告诉我们那些是你喜欢的部分,哪些部分是你不喜欢的或者不清楚的。我们期望能为你做出我们最好的产品。
XNA团队等不及看看XNA Game Studio Express在你的手中可以产生出什么样魔力。
Mitch Walker
program manager | xna framework
原文
What is the XNA Framework
Comments
# re: What is the XNA Framework
# That's a lot of code
# re: That's a lot of code
All it does is create a graphics context and load it into a "Game" application, into which the color blue is drawn into the window.
Especially since from the article it seems the XNA framework would take care of all the library initialization and such (audio, graphics, file I/O, etc...)
Cheers.
# re: What is the XNA Framework
# re: What is the XNA Framework
the actual ability to upload code to the 360 is not expected until later in the year.., or is that the ability to share it?
I think my first task will be to create a controller test tool to represent the selection of each button with a visual action, then look at representing the analogue sticks graphically, baby steps :)
# Let's Kill Dave! : New details about the XNA Framework!
# Mer om XNA Framework.
# re: What is the XNA Framework
I particularly like the idea of being able to play about with an existing game, and getting to learn the language by example, thats how I learnt to code for Neverwinter Nights.
There are going to be an awful lot of beginners out there with as little (or less) knowledge than me. I hope there will be lots of howtos and walkthroughs to stop us from getting frustrated.
Thanks for the update, a good read.
# Alt-Tab, display modes, timers
If you can say at this stage, do you know how we would handle:
1. Alt-Tab. In my games I would like to pause the action when the window loses focus.
2. Display modes.
3. Will it be possible to have a non fullscreen window?
4. Timers. I like to use time-based movement to maintain the same game speed despite the frame rates varying from PC to PC. How do I hook in a timer?
Many thanks,
Peter
# gamedevnews » Blog Archive » More Details on the XNA Framework
# re: What is the XNA Framework
Mark
# First XNA Sample Code
# re: What is the XNA Framework
# What is the future for Managed DirectX?
# re: What is the XNA Framework
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=670758&SiteID=1&mode=1
# re: What is the XNA Framework
# re: What is the XNA Framework
Is the XNA team interested in interns, by chance? Neumont has a program called Enterprise Projects; many students have worked with Microsoft on various projects through the program before. There are half a dozen or so of us about to hit Enterprise Projects this fall or next January that would be extremely interested in something like this.
# re: What is the XNA Framework
I think the trying to keep it available for both platforms is a bit of a silly idea. When we're cranking out 360 games worth playing with XNA, there is no way many people will be able to play these games.
Hopefully the focus is mainly on the 360 end of things. People have already had many easy ways to make games on Windows for years already. Please dont let trying both platforms being compatable "hamper" XNA.
Most(?) of use are just interested in creating 360 games only. With little to no hope of even bothering to have them run on our Windows boxes.
# re: What is the XNA Framework
I think if you took a poll you would find this if far from true!
# re: What is the XNA Framework
The whole effort is to make it easier to develop for windows and xbox not to provide a console centric devleopment API
Development costs are spiraling upwards and especially as xbox live functionalty seems to be coming to vista aswell it makes sense
# Ponder This » Blog Archive » Prepare Yourself and No Content Pipeline
# XNA framework
# Sharky’s Blog » Blog Archive » Some juicy XNA info just out…
# Ponder This » Blog Archive » The First Code Snippets
# XNA Links - 08/28/2006
Mitch Walker does a good job in this...
#
# re: What is the XNA Framework
Actually, the whole point was to open us a console to homebrew. People have been able to have an easy way to program games on Windows for years already. But gaming has pretty much died out on the Windows platforms unless you're an MMORPG addict these days. It's not because of developement costs, it's because people have actually found that console gaming is where it is at, and has finally become powerful enough that they can play their once favorite PC games on their couch with their XBox360. People have been moving to OSX because gaming is less of a concern these days on the home computer. Gamers have migrated onto the consoles FINALLY.
This is why people are excited, now we can have a closed spec system to code on. We can write demos that push the hardware for the system to its limits, use all the cores, and all the interesting GPU functions that dont even exist on home PCs yet. The demos will be mind blowing, and show people the potential of the 360 so long as Microsoft doesn't keep the power from us so it can be "compatible" with Windows.
How many people do you know that have monitors that can output 1920x1080, and do insane 3D operations on their Windows box? The top 1% of gaming PC hardware owners most likely, this is who XNA will appeal to on the Windows side.
I'm sorry if this sounds like a rant, it's not. I appreciate what MS is trying to do. But i'm just pointing out he obvious here, people want to code on the console because it hasn't been available like this ever before. Windows, sure, no big deal, but a next gen console? Especially one that has hardware functions that can't even be replicated on a Windows PC yet? Sign me up!