The sprites will not be aligned to a grid, they’re packed as tightly as doable to protect area (1px spacing). I attempted utilizing Alferd SpriteSheet Unpacker nevertheless it did not work on my picture as a result of the format is nonstandard though it is only a regular png picture. I’m attempting to write down a script with flood fill algorithm to find out the place the sprites are, however I do not know the best way to detect the place the photographs begin and finish.
func separate(picture: Picture) -> void:
var photos := 0
picture.lock()
var begin := {"place": Vector2(0, 0), "previous_blank": true}
var checked_pixels := []
var pixels := [start]
whereas not pixels.empty():
var dict: Dictionary = pixels.pop_back()
var pixel: Vector2 = dict.place
checked_pixels.append(dict)
var clean: bool = picture.get_pixelv(pixel).a == 0
if not clean and dict.previous_blank:
photos += 1
var neighbors := []
if not pixel.x == picture.get_width() - 1:
neighbors.append({"place": Vector2(pixel.x + 1, pixel.y), "previous_blank": clean})
if not pixel.y == picture.get_height() - 1:
neighbors.append({"place": Vector2(pixel.x, pixel.y + 1), "previous_blank": clean})
for n in neighbors:
var found_match := false
for p in pixels:
if p.place == n.place:
found_match = true
break
if found_match:
proceed
for c in checked_pixels:
if c.place == n.place:
found_match = true
break
if found_match:
proceed
pixels.append(n)
picture.unlock()
print(photos)