我的粒子引擎有问题,我试图在我目前正在编码的游戏中实现它。它在黑色背景上看起来不错,但我忘记了如果我添加一个粒子会与背景混合。有什么办法可以防止我的粒子与背景混合,只让它们相互混合?
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();
这里有一些图像向您展示我的意思:
编辑:我通过将其渲染到纹理并将其绘制到屏幕来解决它。这是固定代码:
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();
}