Skip to content

Instantly share code, notes, and snippets.

View codebreadGist's full-sized avatar

codebreadGist

View GitHub Profile
@codebreadGist
codebreadGist / gist:8f12f90664f8a66db37b6f0f3f690f1e
Last active March 2, 2022 23:45
Scrolling, word wrapping text with various colors and font styles (Monogame)
Monogame/XNA doesn't allow you to alter the style of a string in the middle of drawing it, so instead you have to draw each
individual piece of a string if you want to bold or italicize a word. This involves knowing how long each bit of string is
and calling DrawString() for each one, all while making sure they line up correctly. Add in the ability to word wrap and
scroll the dialogue one letter at a time and it becomes a pretty painful problem to solve.
To start, I wrote a function that can take a dialogue box width and a string with special formatting strings embedded in it.
The string used for the text above is this:
"I can't {red}shake {blue}the {green}feeling {normal}that {italics}something {normal}belongs here...
Something extraordinarily {bold}ordinary."