그래서 렌더 타겟에서 결과를 색상 배열로 저장하려고 시도하므로 반복기를 사용하여 개별적으로 조작 할 수 있습니다. 몇 가지 이유로 아래 코드는 배열의 모든 값을 R = 0, G = 0, B = 0, A = 0으로 설정합니다. 마치 초기화되지 않은 것처럼. GetData 메서드가 잘못 사용 되었습니까? 다른 것입니까? 매우 다채로운 이미지 여야하며 분명히 투명하지 않아야합니다.RenderTarget2D에서 색상 배열로 렌더링 오류 저장
텍스처가 제대로 그리지 않는다는 것이 아니라 렌더링 타겟이없는 코드를 실행했습니다 (기본 백 버퍼 사용). 게임은 완벽하게 정상적으로 실행되었습니다.
//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();
감사합니다. 코드에서 spritebatch begin이 누락되었다는 것을 알았지 만, 복사 한 코드에이를 포함시키는 것을 잊어 버린 것이 었습니다. – Kartik