Create wonderful smooth Bézier-, CatMulRom- and Hermite-Splines with TriggerEvents for your MonoGame project.
The Visual Studio 2022 solution contains the following projects:
Note: You don't need this reference if you want to load spline data with Json.Net
Note: You don't need this reference if you don't want to draw your splines. You don't need to draw splines at all. This is just a Debug feature to make your life as a game developer easier ;)
For an easy installation you should make use of the nuget package manager:
So what can this library actually do for you? [Watch the Video!] (Outdated!)
Despite drawing simple lines, it generates very smooth BézierCurves, BézierSplines, CatMulRomSplines and HermiteSplines pretty fast, because it uses polynomial math formulas behind the scenes.
This makes it possible to generate:
Did you notice the different colors of the control points? You can set them in 3 different modes:
Note: A CatmulRomSpline will always have its control points in the Free mode!
You can change control modes simply by clicking on them with the Right Mouse Button in the:
It is also possible to create looped splines as you can see! With the Middle Mouse Button you can drag the whole spline to keep the overview.
Did you noticed the nice little car on the picture? This is a SplineWalker.
A SplineWalker can, well... walk on splines :) or drive on it like in the case of a car, hehe.
You have the abillity to create your own SplineWalkers by inheritting from the SplineWalker class mentioned above.
This could look like this:
public class Car : SplineWalker
{
public override void CreateSplineWalker(BezierSpline spline, SplineWalkerMode mode, int duration, bool canTriggerEvents = true, bool autoStart = true)
{
base.CreateSplineWalker(spline, mode, duration, canTriggerEvents, autoStart);
}
protected override void EventTriggered(Trigger obj)
{
base.EventTriggered(obj);
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
public override void Draw(SpriteBatch spriteBatch)
{
base.Draw(spriteBatch);
}
}
Click here to see a full integration example.
A nice thing about a SplineWalker is, that he can trigger custom events on a spline while he walks along the spline.
You can define your own Trigger with the TriggerEditor:
It is reachable from the main editor through the Tools button.
A SplineWalker also has 3 different built-in movement modes:
It's also possible to define different trigger directions:
Note: It's also possible to control a SplineWalker with your Keyboard or GamePad if you wish so!
You can do pretty much anything with splines. The limit is really just your imagination. Play around with the samples and learn from it.