2
\$\begingroup\$

This question already has an answer here:

I'm a beginner in libgdx, and I'm trying to create my first game. It's pretty simple, circles are falling from the top and sides of the screen, and the user needs to "blow" them before they touch the ground. It is a single screen game, where the world isn't moving, like Tetris.

My problem is that I'm having bad time understanding what viewports should I use, and when.

So, what viewport should I use for this type of game, without generating black bars or stretching the graphics? Will it be possible to check the screen width and height, and act accordingly? let's say the screen is 400x800, can I save it in the code and just spawn the circles out of the screen?

Again, I don't want my graphics to be stretched, since the circles will look weird.

Thanks.

\$\endgroup\$

marked as duplicate by Anko, Community Nov 1 '15 at 13:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ This question has been asked a lot. \$\endgroup\$ – Vaillancourt Oct 31 '15 at 12:25
1
\$\begingroup\$

You might want to use a ScreenViewport or ExtendedViewport. See the libgdx wiki.

You can access the screen size with Gdx.graphics.getXXX() where XXX is either width or height, so you can use this information to spawn your circles outside the current view.

Note that on different screen sizes, your game will feel different, because a bigger screen might make it easier.


Since your question was so general, play around with these viewports and if you have additional questions you can ask a new question.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.