Optimization 新华社;纹理2d“;合并

Optimization 新华社;纹理2d“;合并,optimization,xna,texture2d,Optimization,Xna,Texture2d,如何将多个Texture2D连接到一个大的Texture2D?我试图通过将地图分割成块来优化一个等距平铺游戏 我尝试过谷歌搜索,找到了关于“RenderTarget2D”的文章,但我不确定如何实现这一点 谢谢, 山姆。没关系,我已经解决了 对于任何正在寻找这个的人来说,基本上都可以使用spriteBatch在“RenderTarget2D”上绘制,就像在屏幕上绘制一样 很抱歉解释得不好-我第一次尝试教程。请注意,您的最后一行在XNA 4.0中不起作用。您需要使用GetData和SetData将

如何将多个Texture2D连接到一个大的Texture2D?我试图通过将地图分割成块来优化一个等距平铺游戏

我尝试过谷歌搜索,找到了关于“RenderTarget2D”的文章,但我不确定如何实现这一点

谢谢,
山姆。

没关系,我已经解决了

对于任何正在寻找这个的人来说,基本上都可以使用spriteBatch在“RenderTarget2D”上绘制,就像在屏幕上绘制一样


很抱歉解释得不好-我第一次尝试教程。

请注意,您的最后一行在XNA 4.0中不起作用。您需要使用
GetData
SetData
将其复制到普通的
Texture2D
中。或者您需要处理
RenderTarget2D.ContentLost
。(另见:和)。
RenderTarget2D render;    //declare target

render = new RenderTarget2D(GraphicsDevice, (int)(tileSize.X * numberOfTiles.X), (int)(tileSize.Y * numberOfTiles.Y), 0, SurfaceFormat.Color); //assign target, where tileSize is the size of a tile and numberOfTiles is the number of tiles you are rendering

GraphicsDevice.SetRenderTarget(0, render); //Target the render instead of the backbuffer

batch.Begin();
//draw each tile
batch.End();

GraphicsDevice.SetRenderTarget(0, null); //target the backbuffer again

Texture2D myTexture = render.GetTexture(); //store texture in Texture2D variable