With the default linear filter, the pixels on the edge of a frame are blended with the pixels just outside it, and on a sprite sheet those belong to the next cell. In our Godot 4.7 test a red 16 px frame next to green cells, shown 4 times larger, got a green line 2 px wide on its right and bottom edges: 252 pixels, up to 61% green. Drawn at its own size on a whole pixel it was clean, but at x.75 it had 31 green pixels, and scaled 2.5 times 79. With filter_clip on, every case had 0. The script below turns it on for every frame of a SpriteFrames.
The code
Save it as sheet_clip.gd and load it with const SheetClip := preload("res://sheet_clip.gd"). Call SheetClip.clip_frames($Effect.sprite_frames) once, for example in _ready(), or use SheetClip.cell() to cut a single cell. For frames you made in the editor, you can also tick Filter Clip on each AtlasTexture in the Inspector.
extends RefCounted
## Stop the neighbouring cells of a sprite sheet from bleeding into the edges of a frame.
## const SheetClip := preload("res://sheet_clip.gd")
## SheetClip.clip_frames($Effect.sprite_frames) # every AtlasTexture frame, every animation
## $Icon.texture = SheetClip.cell(sheet, 2, 0, 8, 6) # one cell as its own clipped texture
static func cell(sheet: Texture2D, column: int, row: int, columns: int, rows: int) -> AtlasTexture:
var w := sheet.get_width() / columns
var h := sheet.get_height() / rows
var a := AtlasTexture.new()
a.atlas = sheet
a.region = Rect2(column * w, row * h, w, h)
a.filter_clip = true # sample only inside the region
return a
static func clip_frames(frames: SpriteFrames) -> int:
## Returns how many frames were changed.
var n := 0
for anim in frames.get_animation_names():
for i in frames.get_frame_count(anim):
var t := frames.get_frame_texture(anim, i)
if t is AtlasTexture and not t.filter_clip:
t.filter_clip = true
n += 1
return n
What we measured
A 32 px sheet of 2 by 2 cells: the top left cell red, the other three green. We drew the red cell with an AtlasTexture and counted, on the rendered screen, the pixels with any green in them. Two runs gave the same numbers.
- Linear filter, 4 times larger: 252 pixels with green, the strongest 0.61. With filter_clip: 0.
- Linear, at its own size on a whole pixel: 0. The same at x.75, y.75: 31 pixels, up to 0.44. With filter_clip: 0.
- Linear, 2.5 times larger: 79 pixels, up to 0.51. With filter_clip: 0.
- Linear, 4 times larger and turned 30 degrees: 229 pixels, up to 0.70. With filter_clip: 0.
- Nearest filter, 4 times and 2.5 times larger: 0 both times.
- An AnimatedSprite2D with 3 frames cut the same way, 4 times larger: 252 pixels. After clip_frames() changed the 3 frames: 0.
The red area was the full 4096, 1600 or 256 pixels in every case, so filter_clip did not cut anything off the frame.
Why it happens
The linear filter works out each screen pixel from the 4 texture pixels around the point it lands on. Near the edge of a frame, some of those are past the edge, and an AtlasTexture is only a window onto the whole sheet, so the filter reads the next cell. At its own size on a whole pixel every screen pixel lands on a texture pixel's centre and nothing from outside is used. Scale, rotation or a position between pixels moves those points, so moving or growing effects show the line on some frames and not others. filter_clip limits the reads to the region of the AtlasTexture.
What to change
- A
Sprite2Dthat cuts its own frame with Region instead of an AtlasTexture: turn onregion_filter_clip_enabled. - Pixel art: a Nearest filter (
texture_filteron the node, or the project default) had no bleeding at all in our test, and keeps the pixels sharp. - The same sheet's empty cells: build SpriteFrames and skip empty cells. On particles: flipbook particles that blink out.
- A dark ring all the way round a transparent sprite comes from its see-through pixels, not from the next cell: dark outline around a transparent PNG.
Make your own sheets: PD Flipbook Forge builds VFX flipbook sprite sheets in the browser, with a pixel art mode and a Godot 4 export.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: PD Flipbook Forge builds VFX flipbook sprite sheets in the browser, with a pixel art mode and a Godot 4 export.
More how-tos for PD Flipbook Forge: Stop flipbook particles from vanishing at the end of their life
More how-tos: Play, stop and remove effects
- An aura that comes back when the buff comes back
- A spawned effect that appears exactly where you hit
- Draw the hit effect over what it hit
- Remove a one-shot particle effect when it ends
- Fade out and stop looping particles
- Spawn a hit effect facing the surface
- Hit sparks from a pool of emitters
- Changing one particle effect's color changes all of them
- Particles that play the same way every time
- Freeze particles in mid-air
- Running dust and landing puffs
- Particles left behind by a moving object
- 2D particles follow the player or stay behind
- Footstep particles that match the ground
- A level up effect that plays while paused
- Hide particle effects far from the camera
- Death particles disappear when the enemy is freed
- Remove all particles at once
- Tire smoke that only shows when the car drifts
- Play a 2D sprite sheet effect once and remove it, even if its animation loops
- Sprite sheet frames without the empty cells