3
\$\begingroup\$

My "game" works with a pretty large playing field, so I need a repeating background. I've implemented this the following way:

Loading:

assetManager.get("texture_bg.png", Texture.class).setWrap(Repeat, Repeat);
bgRegion = new TextureRegion(assetManager.get("texture_bg.png", Texture.class));
bgRegion.setRegion(0, 0, 16384, 16384);

Drawing:

batch.draw(bgRegion, 0, 0);

This does as expected: Creates a background of 16384 by 16384 pixels from a 512x512px texture. But now that I'm getting further in the testing, I foresee running out of space quickly almost no matter what I set the region to.

Is there a way I can have it simply repeat forever and not specifying a finite number?

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Could you not just simply add a couple of background images after one another and move the images that are off-screen in front of the character? \$\endgroup\$
    – Charanor
    Commented Nov 8, 2016 at 15:41

1 Answer 1

1
\$\begingroup\$

You don't want to make a Really Large Sprite because it will just look bad when you hit the limits of floating point precision (when it gets larger than 2^24).

it just needs to be at least large enough to cover your screen + an extra 512 pixels, and then just render batch.draw(bgRegion, camera.x % 512, camera.y % 512). Since the texture repeats every 512 pixels, you won't notice that it's moving.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .