So far I've been using sprite.set_texture(get_viewport().get_texture())
and it kind of works, but once I add the sprite to the game using add_child(sprite)
it is placed at the top, over all my other sprites, while I want it to be below them all, so I set .z
on my sprites to 1
and now it's below, but for some reason the generated texture/screenshot only includes graphics that are at or below the sprite receiving the screenshot, everything above gets excluded, which I find strange since get_viewport().get_texture()
should work independently from the sprite receiving it, if I bump its z-index to 1 as well the sprites show up again in the screenshot, but again, the sprites are placed below the screenshot sprite instead of over it, which is not desired.
Here is my code:
extends Node2D
var screen = Sprite.new()
func _ready():
var texture = get_viewport().get_texture()
screen.centered = true
screen.flip_v = true
screen.z = 0
screen.set_texture(texture)
add_child(screen)
func _process(delta):
var texture = get_viewport().get_texture()
screen.set_texture(texture)
If I try to place the sprites on top not with z-index but using an add_child
order the same thing happens.
One idea I have is that maybe there is some rendering pipeline that renders the sprites in the order of the z-index, from bottom to top, and the screenshot is executed not at the end of this process but at the point when the sprite receiving the screenshot gets rendered, and so anything rendered after that (items with a greater z-index) don't get included.
Any ideas?
P.S.
I'm new to Godot, and I'm using Godot 3 Beta 2.