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

本文介绍了使用XNA框架进行游戏开发的基本概念和技术细节,包括GraphicsDeviceManager的初始化、SpriteBatch的使用方法、SpriteFont的加载及绘制文本等内容。

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)

转载于:https://www.cnblogs.com/otomii/archive/2011/04/26/2029092.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值