を事前に
おかげで、Texture2D.FromStream()
方法(MSDN)を使用します。
テクスチャの異なるセクションを描画するには、それを受け入れるSpriteBatch.Draw
のオーバーロードにsourceRectangle
パラメータを使用します(MSDN)。
はここにいくつかのサンプルコードです:
// Presumably in Update or LoadContent:
using(FileStream stream = File.OpenRead("uploaded.png"))
{
myTexture = Texture2D.FromStream(GraphicsDevice, stream);
}
// In Draw:
spriteBatch.Begin();
spriteBatch.Draw(myTexture, new Vector2(111), new Rectangle(0, 0, 50, 50), Color.White);
spriteBatch.Draw(myTexture, new Vector2(222), new Rectangle(0, 50, 50, 50), Color.White);
spriteBatch.Draw(myTexture, new Vector2(333), new Rectangle(50, 0, 50, 50), Color.White);
spriteBatch.Draw(myTexture, new Vector2(444), new Rectangle(50, 50, 50, 50), Color.White);
spriteBatch.End();
Texture2D.FromStreamは感謝多く、このために最適です – Tim