Skip to content
Color · TechniqueBeginner

Hit flash

Push a sprite toward a flat color for a few frames when it takes damage, so the hit reads at a glance.

UVTexture2D / spriteSurface

Cards

One live example to tweak, learn and copy.

How it works

When a character takes a hit, games often turn its sprite white (or red) for a few frames. It costs almost nothing and tells the player instantly that the attack landed, even in a crowded screen. The shader part is small: read the sprite, mix its color toward the flash color by an amount, and keep the sprite’s own alpha so only its silhouette lights up.

The timing lives in game code, not in the shader. The amount is a uniform that the game sets to 1 on the frame of the hit and brings back to 0 over a tenth of a second or so, often together with a short freeze or a knockback. Driving it from the game, rather than from the shader’s time, lets each enemy flash on its own hit.

The sprite still draws with ordinary alpha blending: the flash changes its color, never its coverage. The White flash card shows the basic version; a damage tint (a red flash that fades slower) and an invincibility blink (toggling the flash on and off with time) use the same mix with a different color and amount.

Further reading