Before someone mark it duplicate - I am aware that there are few questions already on this topic but the explanations are all theoretical and no graphical elaboration was provided which I think will help in understanding these concepts better.
Coming to the query in hand, I assume LibGDX
follows OpenGl
definitions of GameWorld
, Camera
and ViewPorts
- please correct me if I am wrong. Now when I am trying to understand these basic concepts of LibGDX
, confusions are arising all around me. I am sure these concepts are not that hard to understand and I must be looking at the things in a wrong way. As per my understanding:
GameWorld Dimensions: This is the dimension of the GameWorld
that I have created, perhaps a Tiled map or some background which will be showing to the player. Lets assume the GameWorld
dimension is 4096 x 4096 px.
Camera Dimensions: This is the dimension of the Camera
that I would like to show to the user at a time. It could be 800x480 px or 320x240 px or whatever I want. When set, user will only be able to see that part of the GameWorld
at a time.
ViewPort Dimensions: I have absolutely no clue how this works!
And my queries are: (Please explain with image/graphics for better clarity)
a. How is ViewPort
related to Camera
?
b. Is Camera
a part of ViewPort
or is it vice-versa?
c. Can Camera
dimensions be different than that of ViewPort
? eg: Can camera be 800x480 px whereas Viewport 320x240 px or vice-versa?
d. When designing games for multiple screen densities/sizes, which is a better approach - Camera
with standard dimensions (16/9 - 4/3 - 800x480) or ViewPort
? If ViewPort
then which is the best in such cases - Stretch
/Fill
/Fit
/Expanded
?