Share via


XNA Game Studio 4.0におけるViewport

XNA Game Studio 4.0ではViewportオブジェクトを使う場面で便利な機能を追加しました。まずは以下のコンストラクタを追加しました。

 public Viewport(Rectangle bounds);
public Viewport(int x, int y, int width, int height);

そして、BoundsプロパティをViewport、Texture2DとPresentationPrametersへ追加しました。

 public Rectangle Viewport.Bounds{ get; set; }
public Rectangle Texture2D.Bounds{ get; }
public Rectangle PresentationParameters.Bounds{ get; }

このことにより、レンダーターゲットと同じサイズのビューポートを設定するのが、以下のように簡単にできるようになりました。

 GraphicsDevice.Viewport = new Viewport(renderTarget.Bounds);

もしくは、テクスチャをビューポートいっぱいに描画するのも、簡単に書けるようになりました。

 spriteBatch.Draw(cat, GraphicsDevice.Viewport.Bounds, Color.White);

原文:

http://blogs.msdn.com/shawnhar/archive/2010/04/14/viewport-tweaks-in-xna-game-studio-4-0.aspx