2

テクスチャ アトラスのタイルに対応する Rectangles の配列があるとします。私がやりたいことは、これらのタイルを取得して、それらから Texture2D オブジェクトを作成することです。基本的には、各タイルのピクセル データを順番に組み合わせて 1 つの画像を形成したいと考えています。どうすればこれを行うことができますか?ここで役に立ちTexture2D.SetData()ますか?

4

1 に答える 1

1
RenderTarget2D target = new RenderTarger2D(...); 
//I cant remeber the arguments off the top of my head.
//I think its GraphicsDevice, Width, Height, GenerateMipmap, SurfaceFormat, Depthformat

GraphicsDevice.SetRenderTarget(target);
GraphicsDevice.Clear(Color.Black); //any colour will do
using(SpriteBatch b = new SpriteBatch(GraphicsDevice))
{
   b.Begin();

   //Loop through all texture and draw them, so ...
   for(int y = 0; y < 10; i++)
     for(int y = 0; y < 10; i++)
       batch.Draw(Texture, new Rectangle(xPos, yPos, width, height), Color.White));

   b.End();
}

GraphicsDevice.SetRenderTarget(null);

//Then to access your new Texture, just do 
Texture newTexture = target; //Target inherits from Texture2D so no casting needed

お役に立てれば :)

于 2013-03-05T13:24:54.693 に答える