在建立新專案前

先了解一下XNA的由來

XNA 全名為 Xbox/DirectX New Generation Architecture。

由於在早期的遊戲開發,大多是使用DirectX來做程式設計部份,

可是DirectX並沒有提供太多的遊戲設計功能,所以開發人員就要負責相當多的部份,例如物件的管理、繪圖順序、遊戲的流程等等,因此提高遊戲設計的門檻,

所以在2006年微軟發表了XNA Game Studio,來改善現有的狀況。 

 

接下來建立一個XNA的新專案 命名為FirstGame

開始偵測 將會出現下面這各XNA的執行畫面

xna.png 

 

當建立一個新專案 系統會幫我們自動生成兩個類別供我們使用

分別為Program 和 Game1

Program 內容很容易了解 主要是透過Main 來run Game1的類別

 

下面是Game1的score code

 


using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;


namespace FirstGame   //namespace後面為我們的專案名稱。
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>

    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;      //此型別提供開發人員一種方式,得以在PC、Xbox360、Zune平台上存取圖形方面的裝置,因此這是一個相當重要的型別。
        SpriteBatch spriteBatch; //此型別是用來繪製影塊的核心物件,以電腦繪圖的術語來說可稱為影塊(sprite)。


        public Game1() //Game1建構式
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }


        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>

        protected override void Initialize()
        {
          //用來初始化Game1物件的相關變數及其它物件,此時你的裝置物件就會被具現化。

            base.Initialize();
        }


        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);     //載入模型、音樂、影像等等


            // TODO: use this.Content to load your game content here
        }


        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>

        protected override void UnloadContent()
        {
            // 釋放掉遊戲用到的物件空間
        }


        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // 更新遊戲的畫面

            base.Update(gameTime);
        }


        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);   //預設遊戲畫面為藍色

            // 繪出遊戲的畫面

            base.Draw(gameTime);
        }
    }
}

 

以上是小弟的小小心得 如有錯誤的地方 請指正謝謝

參考資料:XNA 3.0實戰手冊

arrow
arrow
    全站熱搜

    東勢厝滴yang 發表在 痞客邦 留言(0) 人氣()