Seemless Looping 2D World

Hey guys,

I’m looking to create a 2D game that has a looping world. As in, you go far enough to the right, and you end up on the left and visa versa. I’ve heard that you may need to use 3 different cameras in this situation, but I can’t quite get how you do it.

This is the camera effect I want to achieve:

Any help would be appreciated!
Thanks!

it is vertical but I think many of the same concepts may apply
best of luck

I’ve played with something like this in the past and used the Space Shooter BG_Scroller as a starting off point. To scroll different background images seamlessly I used two images that were side-by-side as in the image below.

We’ll call the images A and B from the left to right, so the camera is starting out only looking at image A.

As the character moved to the right, B shifted into view. When only B is visible to the camera the image pair is reset to its starting location with A’s sprite now holding the image that was originally on B, and with B’s sprite now holding whatever you want to have continuing to the right.

With this setup, if you move to the left you’ll need to jump the image pair the other way immediately. So A’s image gets transferred to B, B’s gets updated with whatever is continuing to the left, and the pair is offset by the image width - your movement.

Edit: more info
For the terrain and game objects then, you’ll either have them randomly spawned or encoded into the larger level design as a flat database like a XML file. For the latter, you’d just need to keep track of the player’s location in the sprawling level and generate the terrain along with the background images being initially populated. The image switching may produce some funny outcomes in the physics initially.

Thanks for the responses guys!

@rakkarage The tutorial you provided only shows a background loop in one direction. I’m looking to loop the whole world seamlessly. I don’t want repeated backgrounds. I want something like portals - that teleport you from side to side, but you can’t tell you’re being teleported. I want to make this multiplayer too just like the video I provided.

@McBugman I don’t want to move any of the backgrounds or scenery. Anytime an object that isn’t background crosses the left or right boundary, I want that object to be teleported to the right or left boundary respectively. But I don’t want the user to realize that their character (or any other moving object) is being teleported.

3519861--281528--tspacexform.gif

I think it is the same but you do both directions and it ends up as a torus or donut
https://godotdevelopers.org/forum/discussion/18108/how-to-create-a-self-wrapping-2d-world-defender

idk good luck

I see what you’re saying. I’ll take a look into those and see what I can do. Thank you for your help!

This is quite an old thread, but here’s a demo where I was able to use a 3-camera approach to pull off seamless looping over a 2D tilemap: GitHub - townofdon/unity-tilemap-loop: A proof of concept for a seamless looping 2D map in Unity

Hope it’s helpful!

2 Likes