Help blending 2 textures together?

Godot Version

4.3

Question

I’m trying to create 1 texture out of 2, so I can assign a sprite to work as a clipping mask. The textures are both 32x32 pixels.

Here is the code I’m using to blend the textures together.
help

When I run this code I want the blended texture to matched up, and contain the full textures like this:
help_2

but instead, when I run it, parts of one texture is missing. They are also not aligned.
help_3
I have no idea what I’m doing wrong. Any help is appreciated. Thank you!

Can you make sure that the textures are the same size by printing the size? And also print out the “image2.get_used_rect()” to make sure its correct. And print the format with “.get_format()” since they need the same

I printed all of that out, and yeah they’re the same size and format. When I print “image2.get_used_rect()” I get: “[P: (6, 8), S: (20, 17)]”. Do you have any ideas of what I could be doing wrong?

The documentation for Image.get_used_rect() says:

Returns a Rect2i enclosing the visible portion of the image, considering each pixel with a non-zero alpha channel as visible.

So as I understand it, it cuts away the sides of the image if those are transparent. You can probably manually construct a Rect2i, something like:

var rect = Rect2i(Vector2i.ZERO, image1.get_size())
image2.blend_rect(image1, rect, Vector2i.ZERO)
2 Likes

This worked perfectly. Thank you so much!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.