1
votes

I have few questions regarding using libgdx viewport.

  1. I have initialised a viewport with this virtual screen size (800 x 480). I'm trying to display a sprite with (100 x 100) virtual size. Do I recalculate based on the screen size ratio to supply the size? Or I just apply virtual size directly to the sprite?
  2. When I initialised a camera, I can supply virtual width and height. I also noticed that, I can supply the virtual width and height when initialising a viewport. Are these 2 different things? Or I just need to supply the virtual width and height either in viewport or camera?
1

1 Answers

1
votes

1) If you are working with a virtual screen size, you will use virtual sizes for your sprites to draw them. If you use a FitViewport with 800x480 size and render a Sprite of (virtual) size 800x480 (you supply these values to the SpriteBatch), then it will fill the whole screen, even if the actual screen would be 1600x960.

2) A Viewport manages the Camera.viewportWidth and camera.viewportHeight for you, based on the strategy that you chose for the Viewport. You can set it yourself, but when you do Viewport.update(...) or Viewport.apply(), the values of your camera will be overridden.