Markup text rendering in XNA

Update: New version, fixed some minor issues, add start()/stop() methods to support the video tag.

Now that I submitted my game to Dream.Build.Play 2011 and I’m all done with it I’ll try to post a few things I made while developing said game and may be useful to other XNA developers.

I’ll start with an update to the markup text engine/thingy I did to display the in-game dialog and help screens (I first wrote about in this post, look there for details and a bit of a tutorial on how to use it). Since that post I added a

Here it is in action, scroll down for source and demo project.

And the markup that generated the image above:



Lorem Ipsum

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.


Temporibus autem

Duis aute irure in reprehenderit.
Velit esse cillum dolore eu dolore eu.

Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum. , temporibus autem quibusdam aut officiis debitis .
Et harum quidem rerum facilis est et expedita distinctio.


At vero eos et accusamus et iusto odio dignissimos ducimus!



Here is a list of supported tags:

  • sets the font and color. Nested text blocks are supported and will inherit any attributes from the enclosing parent tag.
  • obviously specifies an image and has color and scale attributes.
  • specifies a video and also supports the color and scale attributes.

  • adds a line break.
  • inserts a space.
  • is used for conditional rendering.

Download the source code, drop me a note if you use it in your game.

Note: The code is licensed under MS-PL

6 thoughts on “Markup text rendering in XNA

  1. Xerios

    Nice work, I was actually doing something similar and instead of having just a text field, the whole GUI is written in markup language.

    Good luck with your project !

    Reply
  2. DrPool

    Very good idea, with the markup language parsing!

    Just a small ‘bug’: It crashed for me living in France as it seems that the float.Parse(string) method requires a ‘,’ instead of ‘.’ so it fails in the toVector2 Method. Here’s a fix:

    private static Vector2 ToVector2(String vectorString) {
    string[] split = Regex.Split(vectorString, @”[\\s,]+”);
    return new Vector2(float.Parse(split[0], CultureInfo.InvariantCulture), float.Parse(split[1], CultureInfo.InvariantCulture));

    Reply
  3. Carlo B. Corona

    It is awesome! I included in a project of mine and it saved me a lot of work, thank you so much!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *