Tong Quan Ve XNA

Embed Size (px)

Citation preview

  • 7/29/2019 Tong Quan Ve XNA

    1/18

    TNG QUAN V XNA

    Bo co vin: Lng Th Thu H

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

  • 7/29/2019 Tong Quan Ve XNA

    2/18

    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

    Ni dung chnh

  • 7/29/2019 Tong Quan Ve XNA

    3/18

    XNA l g?

    XNA l mt b cng c s dng cho mitrng c thi gian chy game qun lc pht trin bi Tp on Microsoft.

    B cng c XNA bao gm:

    o XNA Framework

    o XNA Build

    o XNA Game Studio

  • 7/29/2019 Tong Quan Ve XNA

    4/18

    XNA Game Studio Express

    XNA GSE l mt t hp cc th vin h tr chovic 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 tngphin bn

    Games c th chy trn mi trng Windowhoc Xbox

    C kh nng pht trin game chuyn nghip vib toolkit ny

  • 7/29/2019 Tong Quan Ve XNA

    5/18

    Cu trc XNA Game Studio Express

    Windows APIs, DirectX

    Common Language Runtime (CLR)

    XNA Framework

    Game code (C#) & content

    You provide Provided for you

  • 7/29/2019 Tong Quan Ve XNA

    6/18

    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

  • 7/29/2019 Tong Quan Ve XNA

    7/18

    Ci t XNA Game Studio Express

    Ci t Visual StudioVisual Studio l mt mi trng tch hp

    (editor/debugger/compiler)

    Nu khng s dng b Visual Studio, chngta cn Visual C# 2008 Express

    Ci t XNA Game Studio 3.0

    Download XNA Game Studio 3.0 ti linkhttp://www.microsoft.com/en-

    us/download/details.aspx?id=15300

    http://www.microsoft.com/en-us/download/details.aspx?id=15300http://www.microsoft.com/en-us/download/details.aspx?id=15300http://www.microsoft.com/en-us/download/details.aspx?id=15300http://www.microsoft.com/en-us/download/details.aspx?id=15300http://www.microsoft.com/en-us/download/details.aspx?id=15300
  • 7/29/2019 Tong Quan Ve XNA

    8/18

    Khi to Project game XNA

  • 7/29/2019 Tong Quan Ve XNA

    9/18

    Cu trc ca Project game XNA Hm to Game1.cs

    public Game1()

    {

    graphics = new GraphicsDeviceManager(this);

    Content.RootDirectory = "Content";

    }

  • 7/29/2019 Tong Quan Ve XNA

    10/18

    Cu trc ca Project game XNA

    Phng thc lm nhim v khi toprotected override void Initialize()

    {

    base.Initialize();}

    Phng thc load ni dung cho game

    protected override void LoadContent()

    {

    spriteBatch = new SpriteBatch(GraphicsDevice);

    }

  • 7/29/2019 Tong Quan Ve XNA

    11/18

    Cu trc ca Project game XNA Phng thc Updateprotected override void Update(GameTime gameTime)

    {

    base.Update(gameTime);}

    Phng thc Draw

    protected override void Draw(GameTime gameTime){

    GraphicsDevice.Clear(Color.CornflowerBlue);

    base.Draw(gameTime);

    }

  • 7/29/2019 Tong Quan Ve XNA

    12/18

    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 trv mt Vector2

    MathHelper

    L mt phin bn ca XNA System.Math

    Hng s: PI, TwoPi, PiOverFour, E, Log10E

    Phng thc: DegreesToRadians, Clamp, CatMullRom, Lerp

  • 7/29/2019 Tong Quan Ve XNA

    13/18

    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

  • 7/29/2019 Tong Quan Ve XNA

    14/18

    iu khin bn phmbanPhim = 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;

  • 7/29/2019 Tong Quan Ve XNA

    15/18

    iu khin chuttoaDoPhiThuyen.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);

    }

  • 7/29/2019 Tong Quan Ve XNA

    16/18

    Initialize LoadContent Game LoopUnloadContent

    (Theoretically)

    Chy mt game XNA

    DrawUpdate

  • 7/29/2019 Tong Quan Ve XNA

    17/18

  • 7/29/2019 Tong Quan Ve XNA

    18/18

    Questions

    & Comments