**This is an old revision of the document!**

How to make a platform game : player animations

This tutorial will explain you how to add different animations and how to use events to change the animations when the state of the player is changing.

Click here to read the previous part if you have not done it already.

Add animations

For now, the player is always displaying the same image: using the events, we're going to change its animation according to what he is doing.

Before doing this, we must add the appropriate animations to the Player object.

Jumping animation

Open the editor of the Player object, make sure you're on the Properties tab, then click on the + button on the bottom of the window to add an animation. Finally, click on the + button of the new animation and choose p1_jump as the image to add:

Animations can be given name, it's an easy way to differentiate between them and use them in the events. It's as simple as clicking on “Optional animation name” and typing the name you want.

Enter “Idle” and “Jumping” as names for our two animations:

Running animation

We need another animation which the one displayed when the character is running on a platform. Add another animation like we did, and, when adding images, select the 5 images p1walk03.png, p1walk04.png, … and p1_walk07.png. Also set the name of the animation to Running:

These images will be displayed so as to create the animation. We need to tweak a bit some options: first click on Don't loop to switch this option to Loop. The timer is displaying the time in seconds between each image. Enter 0.05 instead of 1 so that the animation is faster:

Our object is now ready!

Use events to change animations

The first event: animate when jumping

Now, we need to change the animation displayed by the object according to what the player do. We're going to use the events, which are used to describe the rules of the game and how objects are animated, moved and respond to player inputs. It's a kind of visual programming that can be learn very quickly and is accessible to all.

Open the events editor of the scene by cliking on the tab called New Scene (events).

For now, the events editor is empty:

Add a first event by clicking on the first button to add an event in the toolbar:

An event is composed of a list of conditions (that can be used to check if a collision is happening, if a key is pressed, if the player life is low etc…) and a list of actions that are run when conditions are met.

For now the event is empty:

In this first event, we're going to check if the player is jumping and change its animation. Click on Add condition.

In the window opened, you can see all conditions available in GDevelop for your game in the list on the left. We want to check if the Player object, which has the PlatformerObject behavior, is jumping. Open the category called Platform behavior and then choose Is jumping.

The right part of the window displays the parameter that are needed to configure the condition. Here, we want to check if the Player object is jumping, so choose Player for the first parameter (the second is automatically filled):

The condition is ready! Click on Ok to close the window and see the condition added in the event:

Let's now add the condition to change the Player animation. Click on Add action.

The window opened is similar, but now display all actions available:

We're going to change the animation of the Player, which is a Sprite object. Open the Sprite category, then Animations and finally choose Change the animation (by name).

Select the Player object for the first parameter, and write "Jumping" in the second field. Beware, you have to write the double quotes as any text in GDevelop actions or conditions can also be generated using a formula, so it's necessary to use double quotes to tell GDevelop that this is a text:

When it's done, click on Ok. The first event is ready!

Let's take a look at the result

Click on the Play button in the toolbar to launch a preview. When you jump, the player animation changes!

But when the Player is back on the floor, you can see that the animation is not set back to the Idle animation. This is simply because we never told GDevelop to do so! Let's add another event to do this.