Explosion frames rarely fill their texture: there is empty space around the fireball so it can grow. Scale a 64 px explosion to a 100 px blast radius by its texture size (radius 32) and the biggest frame in our Godot 4.7 test was drawn only 61 to 63 px out, so enemies at 70, 90 and 99 px took damage outside the flash. Measuring the first frame instead went the other way: the last frame went past the edge of the screen. The script below finds the farthest drawn pixel in all frames and scales by that: 97 to 99 px, for an AnimatedSprite2D or a Sprite2D.
The code
Save it as fx_fit.gd and load it with const FxFit := preload("res://fx_fit.gd"). When you create the explosion, before it is shown, call FxFit.fit_radius($Boom, BLAST_RADIUS) with the same radius your damage code uses. The sprite should be centred, which is the default. It reads every pixel of every frame (3.3 ms for 12 frames of 64 by 64 in our test), so call it once per effect, or once per scene you load and reuse the scale.
extends RefCounted
## Scale an explosion (or any round effect) so what is drawn matches a radius in pixels,
## measured from the frames themselves, not from the size of the texture.
## const FxFit := preload("res://fx_fit.gd")
## FxFit.fit_radius($Boom, BLAST_RADIUS) # a centred Sprite2D or AnimatedSprite2D
## It reads every pixel of every frame: call it once when the effect is made, not every frame.
static func visible_radius(tex: Texture2D, alpha := 0.1) -> float:
## Distance from the middle of the texture to the farthest pixel that is drawn.
if tex == null:
return 0.0
var img := tex.get_image()
if img == null:
return 0.0
if img.is_compressed():
img.decompress()
var mid := Vector2(img.get_width(), img.get_height()) * 0.5
var r := 0.0
for y in img.get_height():
for x in img.get_width():
if img.get_pixel(x, y).a > alpha:
r = maxf(r, (Vector2(x + 0.5, y + 0.5) - mid).length()) # to the pixel's centre
return r
static func fit_radius(node: Node2D, radius: float, alpha := 0.1) -> float:
## Returns the largest drawn radius found in the frames, in texture pixels.
var r := 0.0
if node is AnimatedSprite2D:
var frames: SpriteFrames = node.sprite_frames
for i in frames.get_frame_count(node.animation):
r = maxf(r, visible_radius(frames.get_frame_texture(node.animation, i), alpha))
elif node is Sprite2D:
r = visible_radius(node.texture, alpha)
if r > 0.0:
node.scale = Vector2.ONE * (radius / r)
return r
What we measured
An explosion of 12 frames, 64 by 64 px, a white disc growing from radius 6 to 20.3 px, and a damage radius of 100 px. We showed the biggest frame and read, on the rendered screen, how far the drawn pixels reached from the centre in 8 directions. Two runs gave the same numbers.
- Scaled by the texture size (100 / 32 = 3.125): 61 to 63 px. Enemies at 70, 90 and 99 px were hit but outside the flash.
- Scaled by the first frame's drawn size (Image.get_used_rect, 12 px, scale 16.7): the first frame reached 94 to 98 px, the last one 270 px and more, past the edge of the 540 px tall screen.
- The script: farthest drawn pixel 20.26 px from the centre, scale 4.936, the biggest frame drawn 97 to 99 px out.
- The same with the Nearest filter used for pixel art: 97 to 99.5 px.
- A single Sprite2D, a disc of radius 24 in a 64 px texture: 73 to 75 px by the texture size, with enemies at 90 and 99 px outside the flash. The script: 98 to 99.5 px.
- The script with a radius of 60: 58 to 60 px.
The last 1 to 3 px are the steps of a round shape made of square pixels.
Why it happens
Scale multiplies the whole texture, empty pixels included. An explosion drawn with room to grow fills only part of its texture on its biggest frame, so dividing the radius by half the texture width makes the drawn part smaller than the damage by the same share: 20 of 32 px here, about 63%. The first frame is the smallest, so measuring it makes every later frame too big. The farthest drawn pixel over all frames is the one number that matches what the player sees at the moment the explosion is largest.
What to change
- Soft smoke with faint edges: raise the alpha value, the third value of fit_radius(), so the faint pixels at the rim do not count, for example 0.3.
- The script measures from the middle of each frame, so it fits explosions drawn centred in their frames. A ground blast that rises upwards from the bottom of its frame needs its own measure.
- The damage itself: explosion falloff from the edge of the collision shape and explosions that hit through walls.
Ready-made pixel explosions: Pixel VFX Vol 2 Explosions & Smoke has 12 pixel art explosion, fire and smoke effects in 3 colors (fire, blue, green), 64x64 and Godot 4 ready.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: Pixel VFX Vol 2 Explosions & Smoke has 12 pixel art explosion, fire and smoke effects in 3 colors (fire, blue, green), 64x64 and Godot 4 ready.
More how-tos: Fire, smoke and explosions
- Fire that turns to smoke in a cone
- Bright fire with dark smoke
- Smoke particles leave a hard line on the ground
- Particles drawing in the wrong order
- Explosion effect in one burst
- 3D debris particles not rotating
- Particles all disappear at once
- Muzzle flash with a real light
- Glowing particles in Godot 4
- Glowing particles cast dark shadows
- Particles from the surface of a mesh, at runtime
- Fireworks without sub-emitters
- Effects on the beat that stay on the beat
- Make a firework rocket burst at the top of its arc at any launch speed
- Fire or dust over a whole building
- Steam that turns to black smoke when the food burns
- A torch light that flickers the same on every screen