这里有一个抽签区:
graphicsDevice.Clear(Color.CornFlowerBlue);
spriteBatch.Begin();
graphicsDevice.SetRenderTarget(renderTarget);
spriteBatch.Draw(texture2D, position, etc);
graphicsDevice.SetRenderTarget(null);
graphicsDevice.Clear(Color.Red);
spriteBatch.End();这会在红色背景上产生我的Texture2D。为什么这会把我的Texture2D吸引到屏幕上呢?当spriteBatch.Draw被调用时,RenderTarget不是后台缓冲区,我也不会在这段代码中绘制RenderTarget。texture2D不应该显示吗?因为它是从屏幕外画出来的?另外,为什么除非我在结束spriteBatch之前清除屏幕,否则什么都不会显示(只有黑色)??
发布于 2016-11-10 05:27:45
试着像这样整理源代码,
graphicsDevice.Clear(Color.CornFlowerBlue);
graphicsDevice.SetRenderTarget(renderTarget);
spriteBatch.Begin();
spriteBatch.Draw(texture2D, position, etc);
spriteBatch.End();根据我的经验,您需要在实际开始使用sprite批绘制之前设置呈现目标。
至于为什么您的后台缓冲区在完成时是黑色的,这是因为.SetRenderTarget(null);清除了后台缓冲区和呈现目标,这就是为什么屏幕是黑色的(没有)。您应该先完成所有的RenderTarget绘图,所以当您切换回回后台缓冲区时,它不会擦除任何东西。
https://stackoverflow.com/questions/40519668
复制相似问题