Easings and Splines for UI Animations

Index

  1. Introduction and goals

  2. Easings

    2.1. Types of Easings

    2.2. Uses of Easings

    2.3. How does it work

    2.4. Easing Functions

  3. Splines

    3.1. Types of Splines

    3.2. Uses of Splines

  4. Improvements

  5. Pros and Cons

  6. Conclusion

  7. References

1. Introduction and goals

I’m Adrián Aroca, a student of the Bachelor’s Degree in Design and Develpment of Videogames at CITM (UPC). This is my personal research for the subject “Project 2” which is given by Ramon Santamaria, the main developer of Raylib.

My main goal in this research is creating a C++ library that let my class mates create his own animations based on easings and splines for their videogames, as easily as possible. Then, I must do a presentation where I will explain all the content i have prepared, in order to everyone can understand what an easing and spline is, and how they work. Moreover, I need to implement a soulution where I will show how I implemented all the easings types in a Visual Studio project. On this project, I will be able to move a player with any Easing type.

2. Easings

There is no object in real life that just start and stop instantly, and almost never move at constant speed. For example, when you drop a ball from your arms, it first gains velocity (accelerate downwards), and then bounce back up after hitting the floor (accelerate upwards). This is what easings are, and this is what i will explain here. Implementing animations that describes movements of this type frame by frame, would be a nightmare. But, luckyly, there are mathematical functions that can be implemented by coders. And this is something that can diminish the amount of work of animators. Moreover, with that functions, the results obtained will be much more smooth. In the case of the bouncing ball, instead of coding the amount of distance it needs to travel each frame, using easings, you can just give the ball a speed depending on the distance from his objective position.

All the easing functions depends on four parameters:

2.1 Types Of Easings

There are some different types of easings, which can be sorted like that:

First of all, there are 3 easings types:

  1. Ease in: This type of easing, describes the movement of an object with POSITIVE acceleration.
  2. Ease Out: This type of easing, describes the movement of an object with NEGATIVE acceleration.
  3. Mixed: This one, mixes the both previous types (Usually describes a positive acceleration first, and then a negative one).

That 3 types were the biggest types of easing, the most global ones. But, there is a lot of specific functions you can use to describe movements based on easings.

2.2 Uses of Easings

Like said previously, easings are used to create animations that describes accelerated movements by an easy way, because if that animations were created frame by frame, it would suppose a big amount of work, which is boring and unnecessary. Almost all the Software programs dedicated to 2D-3D Animation (For Example, Toon Boom Harmony), uses the easing functions (and most of them let the users previsualize the easing curves ). That allow the users to avoid creating hundreds of frames for a simple movement, and instead it does it automatically taking into account the distance between frames. Easings are also used in the area of Camera views, where the easing functions, allow the users to create a smooth experience and saving a lot of time and work, because they dont need to “Hard Code” the camera progress.

All this is possible thanks to all the Programmers or Coders that implement all the math functions explained here.

2.3 How Does It Work

Now, I’ll explain how splines work in our area, and how to manage them in our project.

Imagine that we have a player and we want to move it by using splines. For example, back splines. We will have the following function:

float position = backEaseIn(currentIteration,initialPosition,deltaPosition,totalIterations);

Our game run at 60 fps and we want that the player movement takes a total amount of 7 seconds, so our totalIterations number will be calculated like this (60 fps * 7 sec = 420 totalIterations). Now we have the totalIterations we’ll need. But we also need to know on each moment which is our current iteration, and we will store that value in “currentIteration”, which starts in zero and each frame it increase one unit, until currentIteration is equal to totalIterations.

float totalIterations = 420;

float currentIteration = 0;

float position = backEaseIn(currentIteration,initialPosition,deltaPosition,totalIterations);

++currentIteration;

Once we know the total iterations and the current iteration, we must decide which will be the initial position, and the delta position (finalPos - initialPos). In our case, let’s suppose that the initial position value is “initialPosition = 0”, and that we desire moving 500 pixels.

float totalIterations = 420;

float currentIteration = 0;

float initialPosition = 0;

float deltaPosition = 500;



float position = backEaseIn(currentIteration,initialPosition,deltaPosition,totalIterations);

++currentIteration;

Right now, this function will return the speed the player needs at each frame to arrive from initialPosition, until finalPosition.

When the path ends, we must reset the number of currentIterations and a bool variable to manage if the easing are activated or not. We must do it because if not, the movement could be infinite. The code will looks more or less like this:

bool easingActivated = false;

totalIterations = 420;

currentIteration = 0;

initialPosition = 0;

deltaPosition = 500;


if (app->input->GetKey(SDL_SCANCODE_Q) == KEY_DOWN)
{

    currentIteration = 0;

    position = 0;

    easingActivated = true;

}

if (easingActivated = true)
{
    position = backEaseIn(currentIteration, initialPosition, deltaPosition, totalIterations);
}

if (currentIteration < totalIterations)
{
    ++currentIteration;
}

else
{
    currentIteration = 0;

    easingActivated = false;
}

This code, should be enough to perform a backEaseIn. But if you want to implement other easing type, is exactly the same, but changing the function you use. For example, if you need to use a exponentialEaseOut, you will just change the name of the function, keeping all the other variables like before.

Video Example of a Golem moving using a backEaseOut (The Hunter Odyssey):

2.4 Easing Functions

3. Splines

In maths area, a spline is a function defined piece by piece, by polynomials. In interpolating problems, spline interpolation is usually preferred over polynomial interpolation because it performs practically the same, even using low degree polynomials, while avoiding Runge’s phenomenon for higher degrees.

In computer science, when you talk about splines, you’re talking about a piecewise polynomial curve. Splines are popular curves on this field because of the simplicity of their construction, their ease and accuracy of evaluation, and their capacity to approximate complex shapes through curve fitting and interactive curve design.

Now, let’s see it from the field we’re interested on, the Animation. Here, a spline is another method for creating animations on an easy way. Using splines, you will be able to create smooth animations just moving curves on a graph. So, using splines, you can do your work easyly, saving your time and effort.

There are some different types of splines, let’s see them.

3.1 Types Of Splines

3.2 Uses Of Splines

The splines are very used in a lot of areas, like I said before. But now, I’ll take a look on a more specific area, Videogames:

In videogames, splines have some uses, but the main is creating paths for the enemies to follow. If you want a smooth motion, the path of the enemies should be continuous (just what splines offers). Other common use of splines in videogames is to design and then define the necessary experience needed to increse levels. Splines are also used in 3D and VR videogames, taking a great importance on camera views, in order to give a smooth camera movement in games where the camera used is the first person (First Person Shooter usually). Moreover, splines are used to create most smoother animations in videogames (also in animation films). Here we have some graphic examples of what I have said on the previous lines:

Here, we can see how splines are used in “Doom Eternal” to give a smooth camera movement to the players.

On “Crash Bandiccot: N.Sane Trilogy”, splines are used to define the path the apples follow until they arrive to his destiny.

4. Improvements

I feel that the main goal I wanted to achieve is done. I created a C++ Library that let to all the developers who want to use it, implement all the different types of easings, moreover on an easy way. But, despite all, I would like to remark some points that could improve the work I did.

  1. Having a code even more polished, and easier to understand.
  2. I would have liked that the Library were defined as a static library, instead creating a source and a header file.
  3. I created a enum class that stored the easing type (cubic,bounce,linear,etc…), but when I tried to use it, the game crashes, so I created that class, but it’s useless and I had to create extra variables in order to store the easing type I wanted.
  4. May be it would be possible to create just a few functions (instead the 33 that I’ve created), that recieving the easing type as parameter, this function reproduce the easing you want.

5. Pros and Cons

The use of easings in videogames can make your work as developer easier in a lot of ways, and it’s hard for me saying a lot of disadvantage about using easings on videogames development. But, I’ll try to say something bad about them.

6. Conclusion

In conclusion, I think that easings and splines are fabulous to any videogames developer. Like i said before a lot of times, they let you make paths, animations, smooth movements, etc…

Without using easings, this work would be slow, heavy and harder. But using them, you will be able to achieve great results (better than if you don’t use them). Moreover, that results will be achieved so much sooner and easily. So, I highly recommend everyone using my C++ Easings Library (or others), and then you will understand why easings and splines like me so much.

I’m glad of the results I’ve obtained after a lot of hours of work, and I must say that the area of splines is very interesting (more than what I expected), and I hope that you find this research as useful as I have found.

7. References

https://medium.com/motion-in-interaction/animation-principles-in-ui-design-understanding-easing-bea05243fe3

https://easings.net/

http://robertpenner.com/easing/

https://github.com/raysan5/raylib/blob/master/src/easings.h

https://github.com/marcgreig/Easing-and-Splines-Research

http://www.animschoolblog.com/2017/07/stepped-or-spline.html

http://euklid.mi.uni-koeln.de/c/mirror/www.cs.curtin.edu.au/units/cg351-551/notes/lect6c1.html