In a lot of the libgdx tutorials that I have took until now, I am told to resize the screen of the game using the SetToOrtho() of the orthographic camera. However, I don't get this part. Why do I have to resize the screen and make the sprites look bigger when I can just make the sprites themselves big at the first place?
1 Answer
\$\begingroup\$
\$\endgroup\$
4
You're not actually "resizing the screen" with setToOrtho
. You're building an orthographic projection matrix that takes into account the size of the screen (note the source).
By doing this, you effectively map the world coordinates of your sprites to pixel coordinates on the screen, which lets you work more naturally in terms of pixel positioning and pixel sizes.
-
\$\begingroup\$ Oh ok thank you for the answer. That makes sense!But this makes me ask another question... An orthographic projection matrix is basically a means of representing a three-dimensional object in two dimensions right? Then why did the tutorial use orthographic projection at the first place when the sprites are already in 2D. (The sprites were flat images) \$\endgroup\$– chanu19Commented Feb 7, 2017 at 16:38
-
\$\begingroup\$ All projections (we use in computer graphics) are ways of transforming and representing 3D geometry in 2D. An orthographic projection is a parallel projection where all projected lines are orthogonal to the plane of projection; in particular it is not a perspective projection and doesn't have that perspective effect of things getting smaller as they are "further" from you. This makes it useful for 2D work. \$\endgroup\$– user1430Commented Feb 7, 2017 at 17:06
-
\$\begingroup\$ Your sprite textures are 2D, but the geometry you draw those textures with is 3D; the underlying graphics API used by libgdx (OpenGL, etc) is a 3D graphics API. \$\endgroup\$– user1430Commented Feb 7, 2017 at 17:07
-
\$\begingroup\$ Ohhh, I never knew that the underlying graphics used by libgdx is 3D and that we change it 2D to render it to the screen. Now it is so clear, Why couldn't the tutorials tell me that :( \$\endgroup\$– chanu19Commented Feb 8, 2017 at 4:52