SVG in XNA

Scalable Vector Graphics (SVG) seemed an ideal format for authoring the enemy paths in Retrofit: Overload but it turned out to be much harder to parse than it appeared at first sight. Fortunately the open-source SVG Rendering Engine works very nicely for reading SVG files in our content pipeline. Here’s how we use it:

Although library source code is available, it’s sufficient to add the Svg.dll to the content importer project’s References. This makes the Svg namespace available. We also need references to System.Drawing and System.Xml.

SVG nodes may have multiple associated transforms. (This is one of the things that makes it impractical to throw together a quick parser for this stuff — There are many ways of representing transformations in SVG, and unless you know that your editor won’t use them, even the simplest SVG data is affected by them.) Fortunately SVGRE parses these for us and stores them with each node. The parsed points are stored untransformed though, so we need to accumulate the node’s transforms and apply them ourselves. Here’s a function to calculate the overall transform that applies to a node.

Hi !! Your post on Scalable Vector Graphics is a worthy stuff. From your blog I learn t how to load the path data in-game. You did an excellent work to present this ,really I appreciate this effort, keep on writing.

Thanks for the helpful article. After poking around with the SVG Rendering Engine for a while, I ultimately decided to load svg documents using generic xml/dom processing tools (using System.Xml.Linq.XElement). This does require stacking your own transformations and interpolating through curves on your own, but otherwise makes it much easier to find and use any svg data you’d like. Best.