Leo
Leo

Reputation: 3143

Libgdx: Infinity world. How to?

I write simple game with libGdx. I have a hero, which always is in screen center and I must move my background sprite (or region?) to make move illusion. But my background sprite isn't infinity.

Of course I can add several background sprites to try to cover all empty space of screen. But I must to draw out of the sceen a lot of all another objects: Houses, monsters, others heroes, etc. So I have a second question:

I know that OrthographicCamera in libgdx draw only viewportWidth-viewportHeight area. If it's right, then I must to move my camera and all my sprites too. I think it's not correctly.

enter image description here

Upvotes: 0

Views: 881

Answers (1)

Aliaaa
Aliaaa

Reputation: 1668

How can I create illusion of seamless infinity world?

Create a tile background. Tile background means that if it was besides or top or bottom of itself, the edges of sticking line will not be visible to viewer.
To do this open your background image in photoshop and go to Filters > Other > Offset. Set the offset filter to offset the background to center then try using photoshop tools to hide the edges (the + shape in image). Now again go to offset and return to 0, 0 and save your background.

When I try to draw other object (a lot of objects!) out of the screen, how badly it affects memory? How to draw it correctly?

I have checked this and that was not much fps loosing on my test. So don't worry about it.

How can I render infinity world in libgdx with OrthographicCamera?

Move camera where-ever you want any x, y. Every time see where is camera and calculate needing tile backgrounds to draw (for example every time draw 3x3=9 backgrounds sticking together).

Upvotes: 2

Related Questions