Drawing on additional viewports

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By TitanicJoe


I have simple tree:


I set margins(right=512,bottom=600) of the VieportContainar to cover half of the screen. Size of viewport from the tree is 512x600. Size of main viewport is 1024x600. I attached script to Node2d in which I draw a rectangle:

extends Node2D
func _draw():

I wander why this rectangle is drawn only on the area autside of aditional Viewport. How can I draw something on this aditional Viewport? How get access to the space of this Viewport to use Physics2DShapeQueryParameters. I dug through documentation, but clearly I don’t understand something important.

What are you trying to achieve btw?

Reloecc | 2020-09-17 07:11

:bust_in_silhouette: Reply From: Reloecc

func draw() is meant to be used to create an art for a node. Like… if you want to create sprite / texture / image for a node, you use draw(). It’s called only once on the app start by default (you may force to redraw() by code if desired). It’s not really meant to continuously render content.

Reason your rectangle is drawn outside of your viewport is that you call draw in you Node2D (root parent). The texture of that node is being drawn, but your viewport’s camera is probably looking at empty space in your scene.