XNAStudy/テクスチャの表示
Last-modified: 2006-12-16 (土) 22:09:50
- プロジェクトを新規作成する。Windowsゲームなので「Windows Game」プロジェクトを選択。
これに手を入れて作っていく。
- graphics変数はプロジェクトを作成した際に既にクラス内に定義されているはず。
- テクスチャの描画
- クラス内に存在する「protected override void Draw( GameTime gameTime )」関数の中
「graphics.GraphicsDevice.Clear( Color.CornflowerBlue );」以下に次の記述をする。
spriteBatch.Begin(SpriteBlendMode.AlphaBlend); // スプライト描画開始
spriteBatch.Draw(Tex, new Rectangle(0, 0, 300, 300), Color.White); // 解説は後述
spriteBatch.End(); // スプライト描画終了
テクスチャの切り抜き
- SpriteBatchのDrawメソッドはオーバーライドされており、引数を変えることで様々に変化させることが出来る。
Draw(2DTexture texture, Rectangle drawArea, Color color )
- 引数
- 2DTexture texture
表示するテクスチャデータ
- Rectangle drawArea
表示先の領域
- Color color
カラーチャンネル
Draw(2DTexture texture, Rectangle drawArea, Nullable<Rectangle> sorceArea, Color color)
- 引数
- 2DTexture texture
表示するテクスチャデータ
- Rectangle drawArea
表示先の領域
- Nullable<Rectangle> surceArea,
描画元領域
- Color color
カラーチャンネル
Draw(2DTexture texture, Rectangle drawArea, Nullable<Rectangle>sourceArea, Color color, float rotation, Vector2 origin, SpriteEffects effects, float depth)
- 引数
- 2DTexture texture
表示するテクスチャデータ
- Rectangle drawArea
表示先の領域
- Nullable<Rectangle> surceArea,
描画元領域
- Color color
カラーチャンネル
- float rotation
回転角度(ラジアン単位)
- Vector2 origin
回転原点
- SpriteEffects effects
反転効果(SpriteEffectsの持つ定数を指定する)
- float depth
スプライトの深度(0~1)の間で指定する
Draw( Texture2D texture, Vector2 pos, Color color)
- 引数
- Texture2D texture
表示するテクスチャデータ
- Vector2 pos
表示する位置
- Color color
カラーチャンネル
Draw( Texture2D Texture, Vector2 pos, Nullable<Rectangle> sourceArea, Color color )
- 引数
- 2DTexture texture
表示するテクスチャデータ
- Vector2 pos
表示する位置
- Nullable<Rectangle> surceArea,
描画元領域
- Color color
カラーチャンネル
Draw(2DTexture texture, Vector2 pos, Nullable<Rectangle>sourceArea, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float depth)
- 引数
- 2DTexture texture
表示するテクスチャデータ
- Vector2 pos
表示する位置
- Nullable<Rectangle> surceArea,
描画元領域
- Color color
カラーチャンネル
- float rotation
回転角度(ラジアン単位)
- Vector2 origin
回転原点
- float scale
拡大縮小
- SpriteEffects effects
反転効果(SpriteEffectsの持つ定数を指定する)
- float depth
スプライトの深度(0~1)の間で指定する
Draw(2DTexture texture, Vector2 pos, Nullable<Rectangle>sourceArea, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float depth)
- 引数
- 2DTexture texture
表示するテクスチャデータ
- Vector2 pos
表示する位置
- Nullable<Rectangle> surceArea,
描画元領域
- Color color
カラーチャンネル
- float rotation
回転角度(ラジアン単位)
- Vector2 origin
回転原点
- float scale
拡大縮小
- SpriteEffects effects
反転効果(SpriteEffectsの持つ定数を指定する)
- float depth
スプライトの深度(0~1)の間で指定する