Interpolation Sample for XNA

One thing I’ve always enjoyed in Silverlight/WPF are the easing functions ( http://msdn.microsoft.com/en-us/library/ee308751.aspx ). The easing functions are commonly used to provide interesting looking animations via key frame-based interpolation.

XNA has a few, limited bits of interpolation built in (primarily Lerp (i.e. linear interpolation) and SmoothStep (i.e. cubic interpolation)). For a sprite animation project that I’ve since set aside (it’s not dead, but it’s been back-burnered for a while now), I replicated most of the Silverlight/WPF easing function (I never got around to figuring out BounceEase and ElasticEase) so that I could use them in XNA. I decided I’d make them available to all of you to use as well. They’re great for spicing up menus and other animations.

The important part of the sample is the Interpolation.cs/Interpolation.vb file; that contains the static class and the two enums that combine together to provide the interpolation. There are two solutions: Interpolation Sample and Interpolation Visualizer. Sample is a basic demonstration of how to use some of the functionality within an XNA game to do things like animate a sprite’s tint color, scale, and position. Visualizer is a WPF app that lets you see what the different enum values produce (and for a few, what the “formula value” does). The code is dual licensed under the MIT License and the. You can get it here:  . The zip files contain both the Interpolation Sample and the Interpolation Visualizer despite the names. Note that the Interpolation Visualizer will need to be built once before you MainWindow.xaml will display properly in the designer due to its use of data binding. Until you build it, it’ll probably tell you that there are errors since it can’t use reflection to find things in an assembly that doesn’t exist yet.

Enjoy!

This article is part of the GWB Archives. Original Author: Michael B. McLaughlin

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.