Wave Engine 2.3.0 (Saw Shark) has added a lot of new features. One of them is a new set of GameActions specialized for animating entities. In this article you may have been realized that GameActions are a really powerful and customizable way to create your own behaviors and interact with others in an easy flow, creating sequential and parallel GameActions to animate your entities. However, they relied on the user the task of creating its own animations as WaveEngine offered the architecture.
Good news is that we’ve included a complete set of GameActions in WaveEngine.Components package. That includes type animations for simple types and transform animations for rotating, scaling and translating entities.
And because they are GameActions, they can be played in sequential order or parallel to others.
Base Type Animations
These animations are the base of the more complex transform animations. This type game actions are used for animating different WaveEngine types (float, Vector2, Vector3 and Quaternion). All of them are similar, they consist in setting an initial and ending value, and passing it an update method that will receive an updated value to work with.
FloatAnimationGameAction
This GameAction is used for animating a float value. In the next code you can see its constructor:
1 |
<em><strong>FloatAnimationBehavior</strong> (<strong>Entity</strong> entity, <strong>float</strong> from, <strong>float</strong> to, <strong>TimeSpan</strong> time, <strong>EaseFunction</strong> ease, <strong>Action<float></strong> updateAction)</em> |
- entity: The entity that will be affected by the game action.
- from: Init value.
- to: Value at the end.
- time: time of the animation.
- ease: Enum of the different easing functions for the game action.
- updateAction: Update action method that will be called every step of the animation and will have a float as a parameter.
For the developer, the updateAction is the key element for animating the entity, because it’s the piece of code that transforms the float value into a behavior.
For example, if we want to make a smooth zoom of a camera3D we only have to animate its FieldOfView property:
var camera3D = cameraEntity.FindComponent<Camera3D>(); var anim = new FloatAnimationGameAction(cameraEntity, 0.79f, 0.2f, TimeSpan.FromSeconds(10), EaseFunction.CubicInOutEase, (f) =>; { camera3D.FieldOfView = f; }); anim.Run();
Vector2AnimationGameAction
This GameAction works in the same way as the previous one but with Vector2. The updateAction method will receive a Vector2 parameter so you can use to animate as you wish. If you are thinking of using this GameAction for translating 2d entities, you may keep reading and take a look at the TransformAnimations.
1 |
<em><strong>Vector2AnimationBehavior</strong> (<strong>Entity</strong> entity, <strong>Vector2</strong> from, <strong>Vector2</strong> to, <strong>TimeSpan</strong> time, <strong>EaseFunction</strong> ease, <strong>Action<Vector2></strong> updateAction)</em> |
Vector3AnimationGameAction
This GameAction works in the same way as the previous ones but with Vector3. The updateAction method will receive a Vector3 parameter so you can use to animate as you wish. If you are thinking of using this GameAction for transforming entities (translating, rotating, scaling), you may keep reading and take a look at the TransformAnimations.
1 2 |
<em><strong>Vector2AnimationBehavior</strong> (<strong>Entity</strong> entity, <strong>Vector3</strong> from, <strong>Vector3</strong> to, <strong>TimeSpan</strong> time, <strong>EaseFunction</strong> ease, <strong>Action<Vector3></strong> updateAction) </em> |
QuaternionAnimationGameAction
This GameAction works in the same way as the previous one but with Quaternion. The updateAction method will receive a Quaternion parameter so you can use to animate as you wish. If you are thinking of using this GameAction for rotating entities, you may keep reading and take a look at the TransformAnimations.
1 2 |
<em><strong>QuaternionAnimationBehavior</strong> (<strong>Entity</strong> entity, <strong>Quaternion </strong>from, <strong>Quaternion</strong> to, <strong>TimeSpan</strong> time, <strong>EaseFunction</strong> ease, <strong>Action<Quaternion></strong> updateAction) </em> |
Transform Animations
On top of the Base Type Animations, we’ve added a set of Transform animations, useful for rotating, translating and scaling your 2D and 3D entities. They inherit the Type Animations, and we’ve added them just for simplification, being really useful for creating simple entity animations.
MoveTo2DGameAction
This GameAction translates the Transform2D component of an entity to a specified position during a specified time.
1 |
<strong>MoveTo2DGameAction</strong>(<strong>Entity</strong> entity, <strong>Vector2</strong> to, <strong>TimeSpan</strong> time, <strong>EaseFunction</strong> ease<strong>, bool </strong>local); |
- entity: The animating entity.
- to: the final position.
- time: Duration of the animation.
- ease: Easing function of the animation. Useful for smooth behaviors (None by default)
- local: If the animation uses local coordinates. (False by default)
MoveTo3DGameAction
This GameAction translates the Transform3D component of an entity to a specified position during a specified time.
1 |
<strong>MoveTo3DGameAction</strong>(<strong>Entity</strong> entity, <strong>Vector3</strong> to, <strong>TimeSpan</strong> time, <strong>EaseFunction</strong> ease, <strong>bool </strong>local); |
- entity: The animating entity.
- to: the final position.
- time: Duration of the animation.
- ease: Easing function of the animation. Useful for smooth behaviors (None by default)
- local: If the animation uses local coordinates. (False by default)
RotateTo2DGameAction
This GameAction rotates the Transform2D component of an entity to a specified angle during a specified time.
1 |
<strong>RotateTo2DGameAction</strong>(<strong>Entity</strong> entity, <strong>float </strong>to, <strong>TimeSpan</strong> time, <strong>EaseFunction</strong> ease<strong>, bool </strong>local); |
- entity: The animating entity.
- to: the final angle.
- time: Duration of the animation.
- ease: Easing function of the animation. Useful for smooth behaviors (None by default)
- local: If the animation uses local coordinates. (False by default)
RotateTo3DGameAction
This GameAction rotates the Transform3D component of an entity to a specified rotation during a specified time.
1 |
<strong>RotateTo3DGameAction</strong>(<strong>Entity</strong> entity, <strong>Vector3</strong> to, <strong>TimeSpan</strong> time, <strong>EaseFunction</strong> ease<strong>, bool </strong>local); |
- entity: The animating entity.
- to: the final rotation.
- time: Duration of the animation.
- ease: Easing function of the animation. Useful for smooth behaviors (None by default)
- local: If the animation uses local coordinates. (False by default)
ScaleTo2DGameAction
This GameAction scaled the Transform2D component of an entity to a specified scale during a specified time.
1 |
<strong>RotateTo2DGameAction</strong>(<strong>Entity</strong> entity, <strong>Vector2 </strong>to, <strong>TimeSpan</strong> time, <strong>EaseFunction</strong> ease<strong>, bool </strong>local); |
- entity: The animating entity.
- to: the final scale.
- time: Duration of the animation.
- ease: Easing function of the animation. Useful for smooth behaviors (None by default)
- local: If the animation uses local coordinates. (False by default)
ScaleTo3DGameAction
This GameAction scales the Transform3D component of an entity to a specified scale during a specified time.
1 |
<strong>RotateTo3DGameAction</strong>(<strong>Entity</strong> entity, <strong>Vector3</strong> to, <strong>TimeSpan</strong> time, <strong>EaseFunction</strong> ease<strong>, bool </strong>local); |
- entity: The animating entity.
- to: the final scale.
- time: Duration of the animation.
- ease (None by default): The easing function of the animation. Useful for smooth behaviors.
- local (False by default): If the animation uses local coordinates.
Easing Functions
All the previous animations can be used with a predefined set of easing functions, passed as an enum parameter in the constructor. In the next diagram, you can learn the different easing functions and their interpolation curves. Chose the one who suits you.
Sample
In the GameActions article, we explained how to create a robot animation. Now we will recreate the same animation with these Transform Animations.
We have a robotic arm model, with the next hierarchy of entities:
In our animation, we will:
- Rotate zone0 180 degrees.
- Rotate zone1, zone2 and zone3 to reach cube1.
- Set visibility of cube1 to false and cube2 to true.
- Rotate zone0, zone1, zone2, zone3 to its initial values.
The next code creates the previous animation and plays it:
// Gets the objects var cube1 = this.EntityManager.Find("cube1"); var cube2 = this.EntityManager.Find("base.zone0.zone1.zone2.zone3.cube2"); var zone0 = this.EntityManager.Find("base.zone0"); var zone1 = this.EntityManager.Find("base.zone0.zone1"); var zone2 = this.EntityManager.Find("base.zone0.zone1.zone2"); var zone3 = this.EntityManager.Find("base.zone0.zone1.zone2.zone3"); var ease = EaseFunction.QuadraticInOutEase; var time = TimeSpan.FromSeconds(1.5); // Play the animation var animationSequence = new RotateTo3DGameAction(zone0, new Vector3(0, -MathHelper.Pi, 0), time, ease, true) .CreateParallelGameActions(new List<IGameAction>() { new RotateTo3DGameAction(zone2, new Vector3(0, 0, 0.087f), time, ease, true), new RotateTo3DGameAction(zone1, new Vector3(0, 0, 0.17f), time, ease, true), new RotateTo3DGameAction(zone3, new Vector3(0, 0, -0.45f), time, ease, true) }).WaitAll() .ContinueWithAction(() =&gt; { cube1.IsVisible = false; cube2.IsVisible = true; }) .CreateParallelGameActions(new List<IGameAction>() { new RotateTo3DGameAction(zone0, new Vector3(0, 0.64f, 0), time, ease, true), new RotateTo3DGameAction(zone1, new Vector3(0, 0, -1.2f), time, ease, true), new RotateTo3DGameAction(zone2, new Vector3(0, 0, 0.9f), time, ease, true), new RotateTo3DGameAction(zone3, new Vector3(0, 0, -1.2f), time, ease, true) }).WaitAll(); animationSequence.Run();
The game will look like this:
SingleAnimations Deprecated
We can say that these GameActions are the successors of the previous animation system. That’s why we encourage you to start using these classes and stop using the classes AnimationUI, AnimationBase and SingleAnimation.