Purpose of Virtual width/height in libgdx java

你。 提交于 2020-03-06 09:32:49

问题


I watched a video by a guy I think is very good with game development, ForeignGuyMike and in his tutorials he uses a virtual width and height and scales it by 2. Here is a screen shot of the code.

I am starting a brand new game and want to know if there is some type of purpose to this. I want to know the pros and cons of this because I can't seem to find where he explains why and where on the internet someone does this. He then multiplies the virtual width and height by the scale for the size of his window. Any help is extremely appreciated.


回答1:


First go through this article by Xoppa, it should clear your basics. But just to understand by an example.

Say you have a screen of width height = 1980x1020px. Now in your game, you hardcode your character size be 100px which looks fine. But if same game is started on a screen of 1280x720px that character of 100px height will be too big.

One way is you use relative values always. For example, take height of screen every time game runs and set your character height be SCREEN_HEIGHT/10. Now you have to follow this everywhere, set character tail height be SCREEN_HEIGHT/11.5 and so on. This could be hard to handle once your game starts to grow.

But if you create a screen camera of say 20x11(virtual screen size) and set character height be 1.2f then no matter what the screen size be, your character size will always be relative to the ratio of height. Because you are working independently from pixels. Everything is explained in the above article by the way.



来源:https://stackoverflow.com/questions/33857063/purpose-of-virtual-width-height-in-libgdx-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!