Viewport and Camera concepts

Godot Version

4.6

Question

I had some issues with them.

Basically I understand a viewport as one screen with the top aligned at the origin
(0,0)of the scene.

I understand a camera as basically one visual screen worth of line of sight centered on the player.

So when I walk, it sometimes has grey backgrounds for areas that are not developed.

I initially solved this by setting the camera limit positions to what was in the viewport.

That worked for boss battles, but as I go into level design, things get more complicated.

Basically my narrow idea of a level was that I could design every part of the level as a scene inside the viewport and then switch to the next scene when u were done and reached an Area2D.

But there were a few problems.

  1. It was hard to design or visualise
  2. Even if u could, it felt flat

So I did away with the "one scene or part of the level fits exactly on the viewport"and began to design the level inside the scene.

The problem is that the level kinda goes up and down, and I am using just sprite background wallpapers to fill it up.

As u move, u see the default grey gaps when something is not developed.

I then tried an Area2D on the background that would reset the camera direction limits when it entered that area, but there are still some issues when u are inbewteen and u want to jump across to the next “Area” but u can’t see it

Does anyone have any advice or suggestions?

Is there perhaps a good video I can watch about this stuff, cause I only know about these things from YouTube tutorials that just gloss over them and teach me how to make the game mostly.

Viewport is a 2d array of pixels in video memory, with given x and y dimensions.
Camera is a transformation/projection matrix that transforms geometry from “world” space to viewport space before it’s rasterized to pixels in the viewport.

1 Like

The terms have kinda got me lost. :rofl:

I just understand it from the screen where I see the blue part and the purple part in the visual editor.

What u saying basically is viewport = area available for user to see

camera = thing that walks around the world and sends what it sees to viewport.

Basically viewport = blanksheet

Camera = visual input from me walking around that fills blank sheet

Almost. Depends what you mean by “area available for user to see”.

The boxes you see in the editor represent the areas of world space that will be “sent” to the viewport by the means of camera projections. The blue box represents the default camera, and the magenta box represents your camera node. If the magenta box is present, it’ll just override the blue box. In other words if you put a camera node in the scene it’ll override the default camera at runtime.

Ah ok… then back to my problem with level design.

So yeah I kinda couldn’t draw and so put a wallpaper background as a Sprite 2Don the position of the default camera.

The thing is as it moves, then the screen goes grey for the parts I put nothing on. I am not sure how to solve it. Someone told me to use a repeatable background with Parallex2D, but then what happens if the user jumps and stuff?

Then because I made the user start at the bottom of my background 3/4 of my camera is grey.

I am kinda like “Nigh fever, nigh fever dunno what to do…” right now :rofl:

Parallax node should do what you want. Not sure what you mean by “what happens if the user jumps and stuff”.

Basically I am worried I will see a gray area cause the user jumps onto a platform cause the camera follows him, so it will move up and stuff. Then it will go out of the default camera angle and them see the gray stuff up there.

Then also what happens if I design a level that kinda elevates you above the default camera angle when u jump onto a platform for example

Parallax2D node can give you “endless” repeating background.

1 Like

2 Likes