Draw a repeating pattern in libGDX

posted in: Android, libGDX | 0

Here is a little snippet, as I was wondering how to repeat a texture as it acts like a pattern with libGDX.

As a background of a game I wanted to draw a pattern that will be full-screen. Using a pattern is a nice way to avoid pixelization with a resource that may be stretched in different ratios and resolutions.

First, create a texture and load your image in the texture. Then from the texture, you’ll tell it that it will repeat.



Then you can simply draw your texture on all the screen:


If you want, you can event increment or modify the third and forth parameter during runtime, this will give a scrolling feeling.


If you need a place to search, download or simply get inspired about background patterns, I suggest you this website: http://subtlepatterns.com/

Or just make a Google search by image including “pattern” and keywords such as “floral”, “wall”, “paper”…

Have fun!