Extract a single column from PNG for Sprite2D in Godot 4.5

Godot Version

Godot 4.5

Question

Hey,

I need to grab one vertical column of pixels from a PNG file and use it as the texture for a Sprite2D in Godot 4.5 at runtime.

Tried Image.load(), ImageTexture.get_data(), and load_png_from_buffer(), but I only get a transparent pixel.

Is there a way to do this in GDScript?

Thanks!

1 Like

You could make an atlast texture:

Screencast_20251122_093621

var atlas_texture := AtlasTexture.new()
atlas_texture.atlas = load("res://icon.svg")
atlas_texture.region = Rect2(14.0, 38.5, 43.0, 42.0) # Right eye
sprite_2d.texture = atlas_texture
1 Like

Works flawlessly, thank you

1 Like