Search code examples
androidlibgdxviewport

How can I implement a ScreenViewport?


I'm new to libgdx and I have a question:

How can I implement a ScreenViewport? I created a new class but I think that is not enough. I'm developing a game and therefore I need the viewport so that every device is gets supported.

I also developed a score but without a viewport the texture will be on different positions on the screen. However, I want it on a certain position! Hope someone can help me. Thanks!


Solution

  • World size of ScreenViewport is based on the size of the screen so for different screen size, you'll get different world size.

    You should take a look of libgdx wiki, and choose appropriate viewport for your requirement.

    I'll recommend you to use ExtendViewport because it keeps the world aspect ratio without black bars. Check this answer.