Flipping Objects in GDevelop



In our previous lesson, we learned how to change the animation of our character “Bob”. We came across a small issue. When we move the player backwards, it doesn’t turn back. In this lesson, we are going to fix that. Well, you may think that we should add a separate animation for that. Nope. We don’t need. We can flip the object horizontally. So the same animation can be used. To do this, we need to update our events.

Step 1

Go to event editor of scene “Level 1”. Select “Bob is Moving” sub task (figure 1) and add two sub tasks under it. Now do to add condition in the first sub event. Find and select Key pressed condition. Select Left (i.e. Left arrow key) as the “Key” from the dropdown. And click OK to add the condition.

Figure 1

Go to add action for this condition and Find and select Flip the object horizontally. Select “Bob” as the “Object” in the settings. Click Yes for “Activate flipping” and click OK. Then add another condition below it. This time, select Change the animation (by name) and select “Bob” as the object. Enter “run” as the animation name and hit OK. Remove the action in “Bob is moving” sub event.





What we do here is, we give instructions to our game that, when we press left key arrow, our character should flip horizontal and then it should play “run” animation. We set “Activate flipping” to “Yes” to tell the game to activate flipping horizontal effect.

Next go to add action for the second sub event. Find and select Flip the object horizontally. Select “Bob” as the “Object” in the settings. Click No for “Activate flipping” and click OK. Then add another condition below it. This time, select Change the animation (by name) and select “Bob” as the object. Enter “run” as the animation name and hit OK. Finally, your events should look like this;


Here we instruct the game to deactivate flipping effect if it is activated (if not it will remain the as it is) and play “run” animation when we press right arrow key is pressed. We set “Activate flipping” to “No” to tell the game to deactivate flipping horizontal effect if it is enabled or else no flipping effect will apply on the object.

Ok, now we are ready to preview our game. Hit the Preview button and move the player back and forth. Now you can see all our animations for player movements work perfectly. Basically, we have created a platformer game. In the next lesson we are going learn how to move camera with the player.

Feel free to ask any question regarding this lesson in the comment section below.