Along with a couple game projects, I have various pieces of tooling and libraries that I’m working on. Today I’m sharing LilyPath, a drawing library for MonoGame and XNA.
LilyPath provides some of the functionality found in System.Drawing
, such as drawing paths and shapes with configurable pens and brushes. Instead of creating raster image however, LilyPath renders everything directly to your scene. Complex paths and filled shapes are rendered as polygons, while primitives are rendered as GL or DX lines.
Drawing is handled through a DrawBatch
object to reduce the number of draw calls needed, mirroring the role of SpriteBatch
for rendering textured quads. More complex geometry can be compiled ahead of time into GraphicsPath
objects, which contain the polygon data after arcs, joins, and other calculations have been completed.
Here’s a short code sample for drawing the lily pad in the picture above (without the flower):
drawBatch.Begin(DrawSortMode.Deferred);
Vector2 origin = new Vector2(200, 200);
float startAngle = (float)(Math.PI / 16) * 25; // 11:20
float arcLength = (float)(Math.PI / 16) * 30;
drawBatch.FillCircle(new SolidColorBrush(Color.SkyBlue), origin, 175);
drawBatch.FillArc(new SolidColorBrush(Color.LimeGreen), origin, 150,
startAngle, arcLength, ArcType.Sector);
drawBatch.DrawClosedArc(new Pen(Color.Green, 15), origin, 150,
startAngle, arcLength, ArcType.Sector);
drawBatch.End();
Source code for the full image and other examples can be found in the included test project, LilyPathDemo
.
I’m currently using LilyPath in a game project for procedural terrain generation, and in a level editor for general annotation support. If you find an interesting use for this library, let me know in the comments.
Are you planning to add support for cubic and quadratic bezier curves?
It’s not a feature that I need right now, but it’s something I’ll probably want in the future when I’m working on path support for my editor.
The good news is that if you can find code to turn bezier control points into discrete points, you can draw those as paths. I’ve used other external code with LilyPath, such as Clipper, to do union or intersection joins on polygons that I want to fill or outline.
Contrary to my previous reply, I decided to go ahead and add this anyway.
Quadratic and cubic Bezier support has now been added in the most recent checkin.
Very cool. I’ve been using a similar thing in my level editor but I haven’t focused a whole lot of energy into it so yours is probably better. I’ll keep an eye on it.
Thanks. I’m also receptive to feedback and PRs.
By the way, has anything been happening lately with your GUI toolkit? I’ll need to compare what’s available pretty soon for some projects.
Sorry I didn’t reply to this comment sooner. I hadn’t been notified about it. I’ve been working on the GUI project lately with brainchest. Take a look at the Trello task board to see what we’ve been up too.. https://trello.com/b/yPijJNWr/craftworkgames-gui
Can you help me, how to use it?
I try add them into my XNA project but it don’t work.
Thanks
Hardwood furnishings possesses one thing very natural about it.
There is this feeling of comfort, of attribute as well as of style that can be actually
be found in hardwood household furniture. Wood is born coming from the planet.
ovlga4
nj0tg5
rkzvl7
5rzg04
zvgugn
zbov92