• 2D
  • How to extend / add data to an Image object.

I am trying to take two image objects with different sets of data, and not merge them on top of each other, but actually add one image to the bottom of another image. (Think sprite sheet rows, and programmatically adding additional rows). I have been reading the GDScript docs on Image and Texture resources trying to find a way to work with image data but it seems to be mostly just a set of convenience functions. (I'm pretty new to Godot but not new to working with image data in C# for other game engines.)

This is all pre-processing so I don't really care if I end up with a very un-optimized solution. I can't even figure out how to just add empty pixels to the bottom of an image, resize function stretches the whole thing out. I'm mainly just setting up some super simple steps to process some non-uniform assets into a more manageable sprite and uniform sprite sheets so the animation code can be a bit simpler.

For example... some of the assets are symmetrical so they have X number of directional rows, expecting the code to flip the asset in the other direction, and other assets are non symmetrical so they have X+N number of rows to cover the additional directions... I am now working with really complicated logic in the animation code to say like "if symmetrical flip it, if not, run a different set of animation frames.. etc." In either case now I'm just really curious how to work directly with Image data so even if there is a better solutions I just want to learn how to get better at working with pixel data directly in GDScript (It doesn't seem this abstracted away in C#)

Maybe @Overloaded knows? They made pixelorama so they may have a better idea on how to manipulate images in Godot. I would offer help myself, but I have never tried any sort of image manipulation in Godot myself.

Edit: Also, welcome to the forums! :smile:

Wow! I resorted to the forums just a tad too soon, Just figured it out on my next try fiddling with things. Its actually as simple as just concatenating the BytePoolArrays of each image!

func add_to_bottom(base: Image, ext: Image):
	var output: Image = Image.new()
	output.create_from_data(
		base.get_width(),
		base.get_height() + ext.get_height(),
		false,
		base.get_format(),
		base.get_data() + ext.get_data()
	)
	return output

How awesome is that? I feel like GDScript is going to continue to catch me off guard for a while just because of how non-convoluted the solutions are after working in more bloated engines for so long :astonished:

@TwistedTwigleg Woah, pixelorama looks awesome! And thanks for the welcome.

I am very much still in the learning the ropes phase of Godot so hopefully you'll start seeing me around more and more and eventually answering questions :tongue: So far my impressions of Godot are great though. I have been looking for a no BS engine like this for game jams and it keeps exceeding my expectations..