I just wanted to take a moment to write about one of my new favourite features of Godot 4.
Tweening! Now this existed in older versions of Godot, but you had to instance a ‘tween’ node in your scene and then reference it through code to get your tween to work.
For those un-aware, a tween in a video development context is to essentially smoothly move a property from one value to another. For example, say you want to make some text fade in, you could tween the alpha channel of that text from 0 to 1 over the course of say a second.
In Godot 4, they made this much easier to do by creating a new helper function called ‘CreateTween’ off of the Scene tree, so you can do things such as…
Tween tween = GetTree().CreateTween();
tween.TweenProperty(this, "modulate", new Color(1, 1, 1, 1), 0.1f);
This would (assuming that the alpha was set to 0 at the beginning) fade in the object over the course of 0.1 seconds. You can chain properties too, like this:
tween.TweenProperty(this, "scale", new Vector3(2, 2, 2), 1f);
If you add that line after the previous two, after 0.1 seconds of fading it, it would double in size over the course of 1s by tweening the scale property to (2, 2, 2). You can also tween other things such as methods (for example, you could Tween a call to QueueFree() to delete a node after X amount of time!)
There are many examples available on the Godot documentation regarding tweening. There are many ways to customize and tweak how the values transition between values. The change in Godot 4.0 to allow you to quickly and easily create a tween programmatically really reduces to barriers to adding tweens to your game on the fly.
I’ve been using it a lot, especially to give more character to the user interface by making things slightly larger or fading in / out.
Will provide updates about projects I’m currently working on soonTM
Leave a Reply