Godot Version
v4.2.1.stable.official [b09f793f5]
Question
I’m trying to extend a TextureRect
for screen transitions in a mobile app. I want the node to take a screenshot of the “target” node. This is the relevant code:
@tool
class_name FadeTransition extends TextureRect
@export var target: Control
func take_screenshot() -> void:
await RenderingServer.frame_post_draw
var region: Rect2i = target.get_global_rect()
var screenshot: Image = get_viewport().get_texture().get_image()
var cropped = Image.create(
region.size.x,
region.size.y,
false,
screenshot.get_format()
)
cropped.blit_rect(screenshot, region, Vector2i.ZERO)
texture = ImageTexture.create_from_image(cropped)
I would like to post more pictures, but as a new forum memeber, I can only add one, so I put here the final result. The FadeTransition
is at the bottom while the white ColorRect
at the top left corner is the target
:
As you can see, not only the white rectangle is being captured.