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
Medium- In
hero.gd, writeflash(): setmodulatetoColor(1, 0.3, 0.3), then tween it back toColor(1, 1, 1)in 0.5 seconds. - 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()
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Projects
1Project: Breakout
Breakout PaddleKeep the Paddle on Screen4Project: Dungeon Crawler
Walk the DungeonPick Up the KeyPractice on your own: Godot playground