所以我试图将渲染目标的结果存储到一个颜色数组中,这样我就可以使用迭代器单独操作它们。出于某种原因,以下代码将数组中的每个值设置为 R=0、G=0、B=0、A=0。好像它从未初始化过一样。GetData 方法是否使用不当?是别的吗?它应该是一个非常彩色的图像,并且绝对不透明。
问题不在于纹理没有正确绘制,我在没有设置渲染目标的情况下执行了代码(使用默认的后缓冲区)并且游戏运行得非常好。
//Creating a new render target and setting it
RenderTarget2D unprocessed = new RenderTarget2D(graphics.GraphicsDevice, Window.ClientBounds.Width, Window.ClientBounds.Height,false,SurfaceFormat.Color,DepthFormat.Depth24,4,RenderTargetUsage.PreserveContents);
graphics.GraphicsDevice.SetRenderTarget(unprocessed);
//Drawing background and main player
spriteBatch.Draw(bgTex,new Rectangle(0,0,Window.ClientBounds.Width,Window.ClientBounds.Height),Color.White);
mainPlayer.Draw(spriteBatch);
//resetting render target
graphics.GraphicsDevice.SetRenderTarget(null);
//creating array of Color to copy render to
Color[] baseImage = new Color[Window.ClientBounds.Width * Window.ClientBounds.Height];
//I pause the program here and baseImage is an array of black transparent colors
unprocessed.GetData<Color>(baseImage);
spriteBatch.End();