← Pixel Dreamer Studio

Sprite sheet frames without lines from the next cell

Turn on filter_clip on every AtlasTexture frame, so the filter only reads pixels inside the frame.

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.

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

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