Menu
CoddyTech

飘动数字

本课属于 Coddy Godot 学习旅程的“游戏体验”单元。第 19 课,共 23 课。

受到攻击时向上飘起的数字会告诉玩家发生了什么。

机器人的 hit() 已经会创建一个显示 -1 的 Label,放在它头顶上方。和箱子的碎片一样,这个标签会添加到 get_parent() 中,因此不会随机器人移动或闪烁。

要让它飘起来,同时将它的 "position:y" 向上移动,并将它的 "modulate:a" 设为 0。补间动画结束后,用 label.queue_free() 移除标签。否则它会留在游戏中,只是不可见。

var rise = create_tween()
rise.tween_property(label, "position:y", label.position.y - 40, 0.6)

tween_property 的第一个值是要更改的节点。这里是 label,而不是 self。

challenge icon

挑战

中等

让 -1 飘起来。

  1. 添加标签后,在 0.6 秒内将它的 "position:y" 向上移动 40 像素。
  2. 同时,将它的 "modulate:a" 渐变到 0.0。
  3. await 这个补间的 finished,然后调用 label.queue_free()。

按“开始”,再按 E:-1 会上升并淡出。然后点击“检查”。

亲手试试

extends Node2D

func hit():
	modulate = Color(4, 4, 4)
	var tween = create_tween()
	tween.tween_property(self, "modulate", Color(1, 1, 1), 0.3)
	var label = Label.new()
	label.text = "-1"
	label.modulate = Color(1, 0.42, 0.42)
	label.position = position + Vector2(-8, -110)
	get_parent().add_child(label)
quiz icon自我测试

这节课包含一个小测验。开始学习即可作答,并记录你的进度。

游戏体验中的所有课

自己练习: Godot 在线编辑器