Hi, I recently realized how I don’t quite understand just how cameras and viewports work together. I have been working on a project (which I’m approaching the point where I will put it up on WIP for public scrutiny) in my free time (that is limited), and used a camera / viewport setup that I saw in a tutorial and it worked for what I needed, so it was forgotten. Unfortunately, when it came time that the tutorial solution was no longer sufficient and tried to modify things that I realized how fragile my grasp of the subject actually is.
I know this seems a basic question, but the documentation on the subject is limited at best, and even with tutorials it seems people just go over their choice with little to no explanation. I’ve been looking over various pages trying to refresh this for myself before asking, and it seems I must be missing something.
Tell me if this is correct, I’ll be working through this over the next few days trying to get how this works, but, the way I understand is that the camera is looking at the scene being drawn (the level plus characters, not libgdx scene), where the viewport is the section of that scene that gets displayed in the window (or android app)? Is this more or less correct?
If this is accurate, Would it be possible / good to either;
- set the camera to be the size of the level (say 100 tiles wide by 20 tiles tall), then set the viewport to see, say 20 tiles wide by 20 tiles tall)?
- Keep the camera and viewport as the same values and just move the camera across the map?
- set the camera to the screen resolution and ignore the viewport?
- any other particular suggestions?
similarly, what is the best strategy to use a viewport that would be suitable for any resolution without the bars of glClear color?
For any box2d scaling issues, I understand what all needs to be scaled, that’s not so much of an issue.
When using viewports in windows, is it possible in the resize event to configure the viewport to compensate for any resolution? For android, is the better strategy to test for the device resolution and configure the display when the program starts?
as a second side question; which strategy would make things easier for things like zooming in an out on the screen?
I think I found one of the downsides to using a game engine, in that I dont really understand how things work, as opposed to with C++ where building everything from scratch meant that I had spent time on every aspect until I came to the solution.
Thanks for any help / answers / advice.