Book Image

LibGDX Game Development By Example

By : James Cook
Book Image

LibGDX Game Development By Example

By: James Cook

Overview of this book

Table of Contents (18 chapters)
LibGDX Game Development By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Handling different screen sizes


On to the final topic of this chapter. One important aspect of game development that needs to be addressed, especially in the world of mobile gaming, is the varying screen sizes that a game can be played on.

Currently, our Snake game is just running against whatever native screen size we have configured in our DesktopLauncher class. If you look at this you will see that in fact we haven't configured any; we have just used the default LibGDX desktop configuration of 640 x 480 pixels.

You might now be wondering why this actually matters. Let's take our Snake game as an example. We currently create a grid of 32 x 32 pixels in which our snake moves around. If the screen size is suddenly doubled, our grid will double in size too. This means it would take the snake twice as long to traverse the screen than it took earlier. However, also consider what would would happen if the screen size was half that size; in that case, the grid would also be half the size.

Maybe...