You are on page 1of 18

I HC CNG NGH THNG TIN V TRUYN THNG B MN TRUYN THNG A PHNG TIN

TNG QUAN V XNA


Bo co vin: Lng Th Thu H

Ni dung chnh
Gii thiu XNA
Cu trc ca mt Project game XNA Xy dng game 2D trong XNA: o Input: Image texture, Audio o iu khin chut v bn phm

XNA l g?
XNA l mt b cng c s dng cho mi trng c thi gian chy game qun l c pht trin bi Tp on Microsoft. B cng c XNA bao gm: o XNA Framework o XNA Build o XNA Game Studio

XNA Game Studio Express


XNA GSE l mt t hp cc th vin h tr cho vic pht trin game 2D v 3D trn my tnh S dng ngn ng chnh pht trin l C# Tch hp vi mi trng Visual Studio theo tng phin bn Games c th chy trn mi trng Window hoc Xbox C kh nng pht trin game chuyn nghip vi b toolkit ny

Cu trc XNA Game Studio Express


Game code (C#) & content

XNA Framework Common Language Runtime (CLR)

Windows APIs, DirectX


You provide Provided for you

c tnh ca XNA
H tr ha 2D & 3D
Truy cp n th vin HLSL (High level shader language)
Pixel and vertex shaders

H tr v m thanh
Cng c h tr m thanh XACT

u vo t bn phm hoc tay iu khin H tr cc font ch H tr mng

Ci t XNA Game Studio Express


Ci t Visual Studio Visual Studio l mt mi trng tch hp (editor/debugger/compiler) Nu khng s dng b Visual Studio, chng ta cn Visual C# 2008 Express Ci t XNA Game Studio 3.0 Download XNA Game Studio 3.0 ti link http://www.microsoft.com/enus/download/details.aspx?id=15300

Khi to Project game XNA

Cu trc ca Project game XNA


Hm to Game1.cs public Game1()
{ graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; }

Cu trc ca Project game XNA


Phng thc lm nhim v khi to
protected override void Initialize()
{

base.Initialize();
} Phng thc load ni dung cho game

protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); }

Cu trc ca Project game XNA


Phng thc Update protected override void Update(GameTime gameTime) { base.Update(gameTime); } Phng thc Draw protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); base.Draw(gameTime); }

Mt s API h tr trong hnh hc


Vector2
+-*/ Normalize, Length, LengthSquared

System.Math
Hm Math.ATan2(x,y) tnh ton gc Hm Cos v Sin tnh gc tr v mt Vector2

MathHelper
L mt phin bn ca XNA System.Math Hng s: PI, TwoPi, PiOverFour, E, Log10E Phng thc: DegreesToRadians, Clamp, CatMullRom, Lerp

V m hnh 2D vi SpriteBatch
Begin
Starts a batch

Draw
Paints a Texture2D to the screen

DrawString
Paints a SpriteFont + a string to the screen

End
Commit the batch

iu khin bn phm
banPhim = Keyboard.GetState();

if (banPhim.IsKeyDown(Keys.Up)) toaDoPhiThuyen.Y -= tocDo;


if (banPhim.IsKeyDown(Keys.Down)) toaDoPhiThuyen.Y += tocDo; if (banPhim.IsKeyDown(Keys.Left)) toaDoPhiThuyen.X -= tocDo;

if (banPhim.IsKeyDown(Keys.Right)) toaDoPhiThuyen.X += tocDo;

iu khin chut
toaDoPhiThuyen.X = Mouse.GetState().X;
toaDoPhiThuyen.Y = Mouse.GetState().Y;

if ( (banPhim.IsKeyDown(Keys.Space)) || (Mouse.GetState().LeftButton == ButtonState.Pressed ))


{ timeDelay += gameTime.ElapsedGameTime.Milliseconds;

if (timeDelay > 100)


{ timeDelay = 0; BanDan(gameTime);

}
}

Chy mt game XNA


Initialize
LoadContent

Game Loop

UnloadContent (Theoretically)

Update

Draw

Questions & Comments

You might also like