Menu
CoddyTech

Hero Flash

Part of the Projects section of Coddy's Godot journey. Lesson 31 of 33.

A lost heart is easy to miss in the top bar. Make the hero flash red when hit, then fade back. A tween does this, in a flash() function on the hero:

func flash():
	modulate = Color(1, 0.3, 0.3)
	var tween = create_tween()
	tween.tween_property(self, "modulate", Color(1, 1, 1), 0.5)

The tint turns red at once, then a tween brings it back to white over half a second. modulate tints the hero and all its children.

main.gd calls $Hero.flash() on every hit. You can call a function on another node through that node.

challenge icon

Challenge

Medium
  1. In hero.gd, write flash(): set modulate to Color(1, 0.3, 0.3), then tween it back to Color(1, 1, 1) in 0.5 seconds.
  2. In main.gd, call $Hero.flash() when the guard touches the hero.

Try it yourself

extends CharacterBody2D

const SPEED = 160

func _physics_process(delta):
	velocity = Input.get_vector("move_left", "move_right", "move_up", "move_down") * SPEED
	move_and_slide()
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Projects

Practice on your own: Godot playground