ビットマップを表示して見ました

ネット上にあまりXna 2.0のサンプルがないので
1.0のサンプルを見ながら書き換えました。

ソリューション内のContentプロジェクト?にリソース保存用のResフォルダを作成し
表示用のビットマップを追加

ビットマップのプロパティのAsset Name をColorBarに変更
ビットマップの追加

ビットマップはこんなの
カラーバー

ソースはこんな感じ (変更していない箇所は省略してます)

Game1.cs
        private Texture2D _characterTexture = null; //ココを追加
 
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            //Content.RootDirectory = "Content";
            Content.RootDirectory = "Content/Res"; //フォルダを作成したので変更
        }
 
 
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
 
 
            // TODO: use this.Content to load your game content here
            _characterTexture = Content.Load<Texture2D>("ColorBar"); //ココを追加
        }
 
       ///<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)
        {
            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
 
            // TODO: Add your drawing code here
            this.spriteBatch.Begin();
 
            this.spriteBatch.Draw(this._characterTexture, new Vector2(100, 100),
                new Rectangle(0, 0, 64, 64), Color.White);         //左から1番目の絵を表示
 
            this.spriteBatch.Draw(this._characterTexture, new Vector2(200, 100),
                new Rectangle(64, 0, 64, 64), Color.White); //左から2番目の絵を表示
 
            this.spriteBatch.End();
 
            base.Draw(gameTime);
        }
実行するとビットマップが2つ表示されます
ビットマップの表示

 

テーマ:プログラミング - ジャンル:コンピュータ

【2007/12/19 00:28 】 | Game作成 | コメント(0) | トラックバック(0) | page top↑
<<ブログペットを変えてみた | ホーム | また迷惑投稿が・・・>>
コメント
コメントの投稿












管理者にだけ表示を許可する

トラックバック
トラックバックURL
http://hekehekemee.blog51.fc2.com/tb.php/7-338bb13f
この記事にトラックバックする(FC2ブログユーザー)
| ホーム |