What is the purpose of that method is and when I have to use it? Really I have no idea. I also found the source code but that didn't help me much.


From looking at the source code, it appears to be used to help translate between "pixel units" and "world units".

[EDIT] [Xoppa's article]1 explains it rather well, but "pixel units" is the number of pixels in your viewport. "world units" is what your game is actually measured in.

For example, suppose you have a table that is 1 meter (world unit) high. If it's far away, you may render it 10 pixels high; if you are closer it may be 100 pixels high. Moving closer changed how big you perceived it to be, and thus changed its pixel size, but didn't change how big it really was (its world unit size).

By default in vanilla libGDX these values are 1:1, but it is useful to keep them logically separate because that way you can change your display size without worrying about messing up your game height. If I know the chair is 1m high, I know a character who can jump 2m can jump over it regardless of how big I draw the character and the chair.

There are occasions where you might need to convert between the two (e.g. raycasting), and I imagine that is when scale would come in handy.

  • \$\begingroup\$ Uhm... thats right. But whats its the difference between "pixel units" and "world units"? And when I'm supposed to use it? When moving something in the game? \$\endgroup\$
    – Wilson X.
    Dec 31 '16 at 16:03
  • \$\begingroup\$ Did you try searching for pixel units vs world units? We have a lot of existing Q&A on that very topic that might help you. :) \$\endgroup\$
    – DMGregory
    Jun 7 '19 at 12:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .