When I was writing my first game in Godot, I wanted to add some simple cut-scenes. First the scene fades in. After a few seconds the bad guy enters. Yet another few seconds later the spotlight turns on and shines on him. Etc, etc.
Of course, I could have made one big Animation that handles all of this, but I wanted something more modular. I also wanted to introduce delays in other parts of the game for cinematic or comical effects. I started adding many Timer elements to all my scenes for each delay and connecting their "timeout" signals to many functions in the code. But that was ugly, and not what I wanted. Basically, what I wanted was something like the "sleep(time)" function I know from other languages.
It turns out that there is a one-liner that gives you that behaviour (to some extent), but it is a one-liner with a lot of baggage.
Snippets of Godot
Explanations of useful GDScript snippets
On-the-fly animations
While the default Animation editor works great if you know the values that you want to animate beforehand, it is not the right solution if you want animations that depend on the current state of your game. For example:
- move and zoom the camera to the player figure or a particular enemy;
- use animations to move a sprite on a grid based on player's input;
- gradually modify the volume of a song based on the player's health bar;
- create fade-in and fade-out effects by animating the alpha transparency of a sprite.
For my most recent game I have created a play_animation function which allows me to quickly create such animations from GDScript:
Subscribe to:
Posts (Atom)