How do I put a camera inside a border

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

I want to make my game run inside a border (like a television border etc) Which nodes I have to use for this?

:bust_in_silhouette: Reply From: Bartosz

Use Sprite for border and attach it as a child of Camera2D
Viewport version would involve few steps:

1.Creating main scene containing “border”, Viewport, and Sprite
2. Creating level scene - actual game that will be played
3. Attaching level.tscn as viewport child
4. setting render_target.v_flip on viewport
5. Attaching into sprite texture new ViewPortTexture
6.setting appropriate dimension of sprite and viewport

here demo of above in my godot-recipes project

erm not so simple like this, i think its something with viewport like this:

ineedle | 2018-03-25 04:10

It is that simple, just ensure that border sprite is at the top. I’ll admit though it is a little wasteful - engine will still try to render those parts of scene that are hidden by border, but today GPUs are smart enough to skip those hidden pixel. So give it a go and if you find that it affects performance to much I’ll explained how to achieve what you want using vieport.

Bartosz | 2018-03-25 13:24

Thankyou very much, I would like to know how to do it using viewport too, for understand better the viewport node use, cause documents doen’t explain cleary

ineedle | 2018-03-25 20:13

check updated answer and look at linked files, if something still unclear ask

Bartosz | 2018-03-25 21:38

it worked perfectly thanks a lot! But the scene inside doesn’t respond, I mean, it has some input codes that doesn’t work, do I have to create setter variables to send the key commands or there’s another easier/better way?

ineedle | 2018-03-25 23:32

I’ve updated linked demo with this code to make input works

extends Node

export(NodePath) var viewport_node = "../Viewport"

onready var target = get_node(viewport_node).get_child(0)

func _ready():

func _input(event):	

Bartosz | 2018-03-26 18:01

Thankyu again, now everything works fine, thankyu very much ^^

ineedle | 2018-03-29 20:31