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.
1 2 |
Texture bg = new Texture(Gdx.files.internal("pattern.png")); bg.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat); |
Then you can simply draw your texture on all the screen:
1 |
batch.draw(bg, 0, 0, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); |
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!