【问题标题】:RenderTarget2D not preserving transparent backgroundRenderTarget2D 不保留透明背景
【发布时间】:2013-05-03 02:02:57
【问题描述】:

我正在做一个项目。全部 2D 使用 spriteBatch。

我让爆炸之类的东西使用了不适用于图像其余部分的自定义效果。到目前为止,这是我的流程:

1)清除背景

2)绘制所有的爆炸精灵

3)捕获该图像并将我的效果实现到单独的 RenderTarget2D

4)画我的背景

5)绘制步骤3中创建的RenderTarget2D

6) 绘制其他所有内容

我遇到的问题是创建的 RenderTarget2D 在未绘制的区域中不透明。因此,第 4 步中绘制的背景没有显示出来。

在对 SetRenderTarget(null) 的任何调用之后,我已经尝试过 GraphicsDevice.Clear(Color.Transparent)。但是,我仍然得到那个紫色背景。

有什么想法吗?

我会发布代码,但是有太多内容需要大家解析。

【问题讨论】:

    标签: c# xna-4.0


    【解决方案1】:

    如果你遵循这个流程,它应该可以工作;

        GraphicsDevice.SetRenderTarget(renderTarget);
        GraphicsDevice.Clear(Color.Transparent);
        // Draw stuff to texture
        GraphicsDevice.SetRenderTarget(null);
    
        GraphicsDevice.Clear(BackgroundColor);  // Important to clear here
        // Draw background
        // Draw texture
        // Draw stuff
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-15
      • 2015-11-12
      • 2011-10-24
      • 1970-01-01
      • 2021-11-25
      • 2017-01-19
      • 2011-03-08
      相关资源
      最近更新 更多