The StateInterpolationPlugin namespace provides a number of useful methods for interpolating (also known as tweening) values using a variety of interpolation types.
The name StateInterpolationPlugin exists for historical reasons - it was previously a plugin that needed to be explicitly installed in the FlatRedBall Editor. Modern FlatRedBall projects automatically include this library, so no plugin installation is necessary. The namespace has remained for backwards compatability.
The TweenerManager is responsible for performing ever-frame logic on tweeners. It can be used to create new Tweeners, inspect existing Tweeners, and interrupt existing Tweeners.
TweenAsync can be used to perform tweening logic using an Action, allowing the assignment of any property. Unlike the Tween function, TweenAsync can operate on any object such as a Gum GraphicalUiElement instance.
The following code shows how to tween an object's X from 0 to 100.
The Tween enables changing any numerical property on an object over a given amount of time using all of the available interpolation types provided by the Advanced Interpolation Plugin. Tween can interpolate any numerical value (like an object's X position). It works on any PositionedObject as an extension method (shown below).
For information on performing tweening with objects which do not implement PositionedObject, see the TweenerManager.TweenAsync method.
The following code shows how to tween the location of a Circle to the edge of the screen when pressing either the left or right keys. This example assumes:
You have a Screen
The Screen has a Circle object. For this example the Circle will be named CircleInstance.
To use Tween to change the position of the Circle based off of keyboard input:
Add the following using statement:
Add the following to CustomActivity:
If your Camera is 2D (default, Orthogonal = true), then zooming requires modifying two values:
OrthogonalHeight
OrthogonalWidth (usually by calling FixAspectRatioYConstant)
Rather than creating two Tween functions that run in parallel, the Tween function allows using a delegate to assign multiple values based on a single value. The example below uses the OrthogonalHeight as the main value, and adjusts the OrthogonalWidth by calling FixAspectRatioYConstant.
Lambdas can be used to assign properties without creating dedicated functions. For example a Circle's radius can be set using the following code:
The tweening logic performed internally by calling Tween is executed regardless of the variable type. That is, the variable does not need an accompanying velocity variable (such as X and XVelocity) to tween properly. Furthermore, since the tweening occurs in the TweenerManager's update, the owner of the variable that is being changed does not need to be automatically updated.