【问题标题】:XNA Additive particles blending on backgroundXNA Additive 粒子在背景上混合
【发布时间】:2013-10-25 20:24:40
【问题描述】:

我的粒子引擎出现问题,我正在尝试在我当前正在编码的游戏中实现该引擎。它在黑色背景上看起来不错,但我忘记了如果我添加一个粒子会与背景混合。 有什么办法可以防止我的粒子与背景混合,只让它们相互混合?

spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone, null);
Main.TileMap.Draw(spriteBatch);
spriteBatch.End();

spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone, null);
Main.ParticleManager.Draw(spriteBatch);
spriteBatch.End();

这里有一些图片可以告诉你我的意思:

http://puu.sh/1O6Zf

http://puu.sh/1O6Yl

编辑:我通过将其渲染为纹理并将其绘制到屏幕来解决它。 这是固定的代码:

    RenderTarget2D renderTarget;
    Texture2D particleMap;
public void LoadContent(ContentManager content)
{
    renderTarget = new RenderTarget2D(Main.graphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, true, Main.graphicsDevice.DisplayMode.Format, DepthFormat.Depth24);
}
public void Draw(SpriteBatch spriteBatch)
    {
        Main.graphicsDevice.SetRenderTarget(renderTarget);
        Main.graphicsDevice.Clear(Color.Transparent);

        spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone, null);
        Main.ParticleManager.Draw(spriteBatch);
        spriteBatch.End();

        Main.graphicsDevice.SetRenderTarget(null);
        particleMap = (Texture2D)renderTarget;

        Main.graphicsDevice.Clear(Color.Black);

        spriteBatch.Begin();

        Main.TileMap.Draw(spriteBatch);
        spriteBatch.Draw(particleMap, new Vector2(0, 0), null, Color.White, 0, new Vector2(0, 0), 1f, SpriteEffects.None, 1);

        spriteBatch.End();
    }

【问题讨论】:

    标签: background xna blending


    【解决方案1】:

    也许这可以帮助你。使纹理半透明:

    spriteBatch.Draw(texture, location, Color.White * 0.5f);
    

    因此,将值从 0.0f 更改为 1.0f 将为您提供透明度强度。

    还要确保你发送了混合状态

    spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend)
    

    【讨论】:

      猜你喜欢
      • 2011-07-15
      • 1970-01-01
      • 2021-07-22
      • 1970-01-01
      • 1970-01-01
      • 2021-04-10
      • 2013-04-28
      • 2014-08-14
      • 2021-07-15
      相关资源
      最近更新 更多