Changing RenderTarget Results in Purple Screen?

时光怂恿深爱的人放手 提交于 2019-12-05 08:26:07

It looks like the best option is to create the RenderTarget somewhere other than Draw, draw to it during Update, save the resulting texture (and manipulate as necessary) then draw that texture during Draw.

I know this is late, but the solution is to write to the RenderTarget BEFORE you clear the screen and beginning drawing your other items.

protected override void Draw(GameTime gameTime)
{
     GraphicsDevice.SetRenderTarget(_renderTarget);

     //...
     //Perform Rendering to the specified target
     //...

     GraphicsDevice.SetRenderTarget(null);

     GraphicsDevice.Clear(Color.CornflowerBlue);

     //...
     //Code that draws to the users screen goes here
     //...
}

This should prevent you from rendering in the Update method as suggested by others, which is counter-intuitive in many aspects.

Christopher Ross

When spritebatch.End() is called objects are written to the backbuffer or in your case to tempTarget. To make the texture,

  • change the target
  • call begin
  • call all of the draws
  • end the spritebatch
  • set target back to null

then use the render2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!