【发布时间】:2012-08-24 16:31:35
【问题描述】:
我的问题是我试图将两个不同的 RenderTarget2D 绘制到屏幕上,但只显示最后绘制的一个。代码与以下类似,并被调用两次,一次由需要使用Draw 方法绘制的类的每个实例调用:
public override void Draw()
{
gfxDevice.SetRenderTarget(myRenderTarget);
gfxDevice.Clear(Thistle);
//pseudocode
foreach (something in a list)
{ spritebatch.begin();
spritebatch.DrawString(something);
spritebatch.end();
}
//reset to the backbuffer
gfxDevice.SetRenderTarget(null);
gfxDevice.Clear(backgroundColor) //Here is what I thought the offending line was
//draw the RenderTarget to backbuffer
spriteBatch.Begin();
spriteBatch.Draw(myRenderTarget, rect, this.backgroundColor);
spriteBatch.End();
我认为解决方案是在每次调用Draw() 方法时停止清除graphicsDevice,但如果我不这样做,除了新绘制的渲染目标之外的所有东西都会被绘制成丑陋的紫色。像这样:
紫色的结果来自End()ing spritebatch,我想,感谢this question
我需要进行哪些更改才能正确绘制两个 RenderTargets,这意味着绘制两个小部件以及正确的 Color.Thistle 背景?
理想情况下,屏幕看起来应该是两者的组合: 和
【问题讨论】: