4
\$\begingroup\$

Is there a way that I can add shadow effect on text drawn in monogame? Because you cannot add shadow effect when creating a new spritefont file in Monogame Content Pipeline.

Thanks.

\$\endgroup\$
5
\$\begingroup\$

One way to do this, is to draw your text 2 times in a different color at specific offsets.

For example:

    public static void DrawText(SpriteBatch spritebatch, SpriteFont font, string text, Color backColor, Color frontColor, float scale, Vector2 position)
    {
        Vector2 origin = Vector2.Zero;

        spriteBatch.DrawString(font, text, position + new Vector2(1 * scale, 1 * scale), backColor, 0, origin, scale, SpriteEffects.None, 1f);
        spriteBatch.DrawString(font, text, position + new Vector2(-1 * scale, 1 * scale), backColor, 0, origin, scale, SpriteEffects.None, 1f);
        //spriteBatch.DrawString(font, text, position + new Vector2(-1 * scale, -1 * scale), backColor, 0, origin, scale, SpriteEffects.None, 1f);
        //spriteBatch.DrawString(font, text, position + new Vector2(1 * scale, -1 * scale), backColor, 0, origin, scale, SpriteEffects.None, 1f);          

        spriteBatch.DrawString(font, text, position, frontColor, 0, origin, scale, SpriteEffects.None, 0f);
    }

Might be good enough for what you are trying to do.

\$\endgroup\$
  • \$\begingroup\$ Thank you very much. What about creating a nice text outline? The two commented lines + the above are for it? \$\endgroup\$ – Edvin Jul 3 '15 at 16:46
  • \$\begingroup\$ @Edvin Yes exactly, If you uncomment the two lines, it will produce an outline. \$\endgroup\$ – jgallant Jul 3 '15 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.