1

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

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();
    }
4

1 回答 1

0

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

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

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

还要确保你发送混合状态

spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend)
于 2013-10-25T12:24:40.787 回答