1
\$\begingroup\$

So, I read that camera = new OrthographicCamera(1, h/w); creates a camera with an appropriate width and height for the field view.. However, I can't understand that value 1 for the viewport width, does a value 1 means full width?

\$\endgroup\$
1
\$\begingroup\$

You need to distinguish between the gl-viewport and the cameras viewport. The GL-viewport somehow defines the area on the Display, while the cameras viewport defines the area in the game world.

So a camera with a viewport of (1/1) can see 1 unit of your world in width and height and projects it to the gl-viewport.

For example: You have a Camera with a viewport of (16,9) and it's center is at (8, 4.5), the middle. Now you can see all objects form P(0,0) to P(16,9). Objects outside this area are not visible to you.

You may ask, which values you should use. That depends on the game, but to find a good value, you may think about them like meters. How many meters of your gameworld you want to see at once? For example if you have a 1m tall character. How much space should he take on screen? If it's 1/9 of the screen, your viewport hight should be 9.
One important note: You should definitly use Viewports, they have some additional functions, which are usefull in many cases.

\$\endgroup\$
  • \$\begingroup\$ I'm new to game dev so please don't judge me, I'm still kind of confused with all this concepts.. Tell me if I'm wrong.. We have our device display, what our viewport does is like selecting what part of our game world we see in the display, right? Also, our game world size isn't directly connected to the display size, right? It can be whatever the size we want for our game.. \$\endgroup\$ – yat0 May 7 '15 at 22:55
  • \$\begingroup\$ @polska Exactly. The camera just "selects" the part of your gameworld and projects it to the display. It is independend of the resolution and display size. The glViewport instead defines the "drawable" area on screen. \$\endgroup\$ – Springrbua May 8 '15 at 6:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.