When using this code:
public static Texture2D ShowHealthBar(SpriteBatch spriteBatch,Texture2D empty, Texture2D full, float health)
{
spriteBatch.Begin();
RenderTarget2D healthBarTarget = new RenderTarget2D(Game1.graphics.GraphicsDevice, full.Width, full.Height);
Game1.graphics.GraphicsDevice.SetRenderTarget(healthBarTarget);
spriteBatch.Draw(empty, new Vector2(0, 0), Color.White);
Game1.graphics.GraphicsDevice.SetRenderTarget(null);
spriteBatch.End();
return (Texture2D)healthBarTarget;
}
the texture is purple.
When inserting Game1.graphics.GraphicsDevice.Clear the texture has the clear color.
Why doesn't the sprite batch work?
GraphicsDevice.SetRenderTargetoutside of your calls toSpriteBatch.BeginandSpriteBatch.End. \$\endgroup\$