代码改变世界

WP7备注(2)(XNA基本元素)

2011-04-26 11:17  血糯米Otomii  阅读(239)  评论(0编辑  收藏  举报

GraphicsDeviceManager :

以XNA为基础的游戏程序必须在初始化的时候声明GraphicsDeviceManager的对象,并设定游戏界面的高度与宽度:

GraphicsDeviceManager graphics;

graphics = new GraphicsDeviceManager(this);

graphics.PreferredBackBufferHeight = 480;

graphics.PreferredBackBufferWidth = 800;

GraphicsDevice:

Buffer背景颜色

GraphicsDevice.Clear(Color color)

SpriteBatch:

SpriteBatch 主要显示2D图像,包括游戏背景、游戏人物、游戏的状态和菜单

SpriteBatch spriteBatch;

spriteBatch = new SpriteBatch(GraphicsDevice);

SpriteBatch 进行DrawString

spriteBatch.Begin();

spriteBatch.DrawString(segoe14, text, textPosition, Color.White);

spriteBatch.End();

Viewport:

Viewport主要表示一个二维的Rectangle(X,Y,Width,Height)

获取设备的Viewport:

Viewport viewport = this.GraphicsDevice.Viewport;

SpriteFont:

加载:SpriteFont spriteFont= this.Content.Load<SpriteFont>("spriteFont");

Texture2D:

Texture2D segoe14 = this.Content.Load<Texture2D>("texture2D");

SoundEffect:

SoundEffect soundEffect= ScreenManager.Game.Content.Load<SoundEffect>("soundEffect");

Vector2:

获取SpriteFont描述的字体对于相应文本所占有的二维空间坐标(X,Y)

Vector2 textPosition = spriteFont.MeasureString(text)