A Coin That Pops
Part of the Game Feel section of Coddy's Godot journey. Lesson 7 of 23.
When you touch a coin, it disappears at once. A short pop shows the player they picked it up. The coin grows and fades, then it is removed.
The pop is a tween with two steps that run together. The coin must stay until the tween is done. A tween sends the finished signal when its last step ends, and await waits for it.
var tween = create_tween()
tween.tween_property(self, "scale", Vector2(2, 2), 0.3)
tween.parallel().tween_property(self, "modulate:a", 0.0, 0.3)
await tween.finished
queue_free()await tween.finished pauses the function until the tween ends. Then queue_free() runs. The rest of the game keeps running while it waits.
Challenge
MediumMake a coin pop before it goes.
- In
_on_body_entered, tweenscaletoVector2(1.8, 1.8)in0.25seconds. - At the same time, tween
"modulate:a"to0.0. - Wait for the tween to finish, then
queue_free().
Press Play and walk into a coin: it swells and fades away. Then Check.
Try it yourself
extends Area2D
func _ready():
body_entered.connect(_on_body_entered)
func _on_body_entered(body):
queue_free()
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Game Feel
1Tweens
Your First TweenTween Any PropertyFade OutEase OutOne After AnotherAt the Same TimeA Coin That PopsPractice on your own: Godot playground