I have a large level design & I'm trying to take a pixel perfect screen shot of a particular area and/or the entire map bound within a region like this:
The region can be changed in size and position so I used a ReferenceRect
( Green box in the image) node to manually change it
So far I've come up with this:
extends ReferenceRect
func capture_image():
var viewport=get_viewport()
viewport.set_size_override(true, Vector2(rect_size.x, rect_size.x * viewport.size.y / viewport.size.x ))
var image = viewport.get_texture().get_data()
image.flip_y()
image.save_png("res://screenshot.png")
print("Took Screenshot!")
func _unhandled_input(event):
if event is InputEventKey:
if event.pressed and event.scancode == KEY_SPACE: # try pressing space twice
capture_image()
This fits the entire game within the screen window but the image generated does not give a pixel perfect screenshot & the image size/resolution remains 1024 x 600 pixels
as you can see:
I suspect the window size itself would have to be increased to fit the ReferenceRect
in order to get a pixel perfect screenshot
So is it possible to achieve this?
A crude method would also work since this is purely for development stage
Note: I'm using godot v3.5
Add this script to the
ReferenceRect
& extend its borders to encapsulate the area to screenshot & press space:Note:
As per the docs:
so the
rect_size
for theReferenceRect
you attach this script to cannot exceed (16384 x 16384) sucks :/On the bright side the limit for this in Godot 4 is
16777216 x 16777216
which is much more better but I haven't gotten to that, so feel free to translate the above code to Godot 4