Your sword connects, the enemy loses health, and nothing on screen says so. You want the classic hit flash: the sprite goes solid white for a moment, then back to its colours. In Godot 4 the first thing most people try is modulate = Color.WHITE, and nothing happens. The next try is a bright modulate like Color(10, 10, 10), and the slime turns a washed-out cyan with a dark rim. Or the flash works, and every slime on screen flashes when you hit one of them.
This guide fixes all three. The shader and the script below were run in Godot 4.7.2 on a 16x16 slime from our Pixel Monsters, and every pixel of each result was read back from the GPU and checked.
Why modulate can't make a sprite white
Modulate multiplies. Each channel of each pixel is multiplied by the modulate colour, so Color.WHITE, which is 1 in every channel, is the one value that changes nothing. Multiplying can darken a sprite or tint it. It only reaches white when the result goes over 1 in all three channels and gets clipped there.
That is what a value above 1 does. With HDR 2D off, which is the default (Project Settings, Rendering, Viewport), every channel is clipped at 1. Our slime has 93 visible pixels, and this is what modulate did to them:
- Color(2, 2, 2) turned 5 of the 93 pixels white.
- Color(10, 10, 10) turned 62 of them white. The dark green outline, #143519, came out pale cyan, #c8fffa.
- Color(100, 100, 100) turned all 93 white, and only because the outline isn't pure black. A pure black pixel stayed #000000 and a pure red one stayed #ff0000. A channel at 0 stays 0 whatever you multiply it by.
So modulate is fine for a red damage tint or a fade, and it needs no shader. For a true white flash on art with black outlines or saturated colours, you need a shader that replaces the colour.
The hit flash shader in four lines
Select your Sprite2D or AnimatedSprite2D. In the Inspector, open CanvasItem, then Material, and pick New ShaderMaterial. Click it, pick New Shader in its Shader slot, set the mode to Canvas Item and save it as hit_flash.gdshader. Replace the template with these four lines:
- shader_type canvas_item;
- uniform vec4 flash_color : source_color = vec4(1.0);
- instance uniform float flash_amount = 0.0;
- void fragment() { COLOR.rgb = mix(COLOR.rgb, flash_color.rgb, flash_amount); }
At flash_amount 0 the sprite draws exactly as before: we compared all 256 pixels of the frame. At 1 every visible pixel becomes flash_color and every transparent pixel stays transparent. At 0.5 each pixel sits halfway between its own colour and white. The value also shows in the sprite's Inspector, so you can drag it to preview the flash.
Each line is there for a reason:
- It edits COLOR instead of reading texture(TEXTURE, UV). In a canvas_item shader, COLOR already holds the texture multiplied by the node's modulate, so the sprite keeps its fade. In our test a slime at 50% modulate alpha flashed white at half strength, and a slime tinted red by modulate flashed pure white. A version built on texture(TEXTURE, UV) flashed fully white at 50% alpha and lost the fade.
- Only rgb changes, so the shape stays exactly the same. A test pixel with half alpha came out half see-through and white.
- flash_amount is an instance uniform, so each sprite holds its own value while every enemy shares one material.
- flash_color is a normal uniform, shared by everything that uses the material. Leave it white for enemies, and give the player its own copy of the material with red for when they get hurt.
Why every enemy flashes at once
If flash_amount is a plain uniform and you set it with material.set_shader_parameter(), you get the other classic bug. The material is a resource, and every enemy made from the same scene uses that one resource. In our test, setting the value on one slime turned both slimes on screen white. There are two fixes:
- Use an instance uniform, as in the shader above: one material, one value per node. Set it with set_instance_shader_parameter("flash_amount", 1.0). Only the slime we hit turned white.
- Or tick Local to Scene in the ShaderMaterial's Resource section. Each instance of the scene then gets its own copy of the material. In our test the two slimes no longer shared one, and only the hit one flashed.

Timing the flash in frames
Godot runs physics 60 times a second by default (Project Settings, Physics, Common, Physics Ticks per Second), so one tick is about 16.7 ms. Counting ticks lets you think about the flash in frames, the way an animator does.
The Pixel Monsters README gives the hurt frame about 0.1 s. That is 6 ticks, so it is the flash length we use. This script goes on the enemy's root Node2D, with an AnimatedSprite2D child that has the material and two animations, move and hurt (hurt not looping):
- extends Node2D, then const FLASH_FRAMES := 6, @onready var sprite: AnimatedSprite2D = $AnimatedSprite2D and var flash_until := 0.
- In _ready(): sprite.animation_finished.connect(func(): sprite.play("move")), then sprite.play("move").
- func hit() -> void: flash_until = Engine.get_physics_frames() + FLASH_FRAMES, then sprite.set_instance_shader_parameter("flash_amount", 1.0) and sprite.play("hurt").
- In _physics_process(_delta: float): if flash_until > 0 and Engine.get_physics_frames() >= flash_until, set flash_until = 0 and sprite.set_instance_shader_parameter("flash_amount", 0.0).
The script stores the tick when the flash ends instead of counting down, so the flash lasts the same number of frames whether hit() runs before or after the enemy's own _physics_process. Run at a fixed 60 fps, the slime drew exactly 6 white frames after hit(), showed its hurt frame under the flash and went back to its move loop.
How long the flash should last and when it starts
- Start the flash on the frame the damage lands. Our Combat VFX pack marks the hit frame of every effect in its JSON. The steel hit spark lands on its first frame and plays 5 frames at 15 fps, so the spark and the flash start together.
- Hold the flash at full white on small sprites. A 16x16 enemy has few pixels to fade through, so 4 to 6 ticks of solid white is the usual choice.
- If you want a fade on bigger sprites, tween the same value: create_tween().tween_property(sprite, "instance_shader_parameters/flash_amount", 0.0, 0.1).from(1.0). In our run it went 0.833, 0.667, 0.5, 0.333, 0.167 and 0 over six ticks.
- Keep the flash shorter than the gap between hits. A weapon that hits every few frames restarts the timer each time, and the enemy just stays white. Two or three ticks suit fast weapons.
- Give the player a different signal, such as the red flash_color or a blink, so the player being hurt never looks like an enemy being hit.
Bosses take many hits
A boss is hit far more often than a slime, so flash on every hit and play the hurt animation only some of the time. Each boss in Pixel Bosses has a 3-frame hurt at 10 fps, which is 0.3 s or 18 ticks. A boss that flinches at every hit can be stun-locked, and the flash alone still tells the player the hit counted. The JSON also lists the frames where the boss's own attack hits, so the player's flash can start on those frames too. More on phases and hit boxes in boss fight design in pixel art.

Sprite sheets and AnimatedSprite2D
The shader works on whatever the node draws, so it behaves the same on a Sprite2D, an AnimatedSprite2D, or frames cut from one sheet with AtlasTexture regions. We built the slime's SpriteFrames from the 1x sheet in Pixel Monsters, four move frames and the hurt frame, each a 16x16 region, and the hurt frame flashed white pixel for pixel. If your sheet isn't in Godot yet, see how to import pixel art sprite sheets into Godot 4. The Godot Animation Scene Builder turns a sheet into SpriteFrames and a ready scene, and the material goes on its AnimatedSprite2D the same way.
Checklist
- Modulate multiplies: Color.WHITE changes nothing, and black stays black at any value.
- Edit COLOR in the shader, so modulate fades and tints still apply.
- Use an instance uniform or Local to Scene, so one hit flashes one enemy.
- Count the flash in physics ticks from the frame the damage lands. Six ticks is 0.1 s at the default 60.
- On enemies that take many hits, flash every hit and play the hurt animation only some of the time.
Every creature in Pixel Monsters has a hurt frame and a 4-frame death, the bosses have hurt and death in both phases, and Combat VFX has the hit sparks, impacts, criticals and parry to play on the same frame as the flash.
Our packs can go in commercial games but not be resold as files; see can I use game assets in a commercial game. If you need a monster or a boss drawn for your game, you can order a custom pack.