How to handle a game world that wraps

Forums Programming Programming – Everything else How to handle a game world that wraps

This topic contains 1 reply, has 2 voices, and was last updated by  RossyP 2 years, 1 month ago.

Viewing 2 posts - 1 through 2 (of 2 total)
Author Posts
Author Posts
February 22, 2012 at 12:32 pm #239400

Tiddlypeeps
@tiddlypeeps

I have a game world that’s much bigger than the view port, the main character stays in the center of the view port at all times and the background layer is moved around to give the impression of the character moving. I want to make it so that the game world wraps, meaning if the the character keeps traveling either left or right they will eventually end up back at the starting position. There will be moving entities in the game world so the biggest problem I foresee is that if you go to the far right of the map you should be able to see any of the moving entities that are within the first small section of the far left of the map.

I’ve thought a bit about this and any solution I’ve come up with seems far too complicated. Like creating two identical game worlds side by side and moving them around accordingly. I live in hope that there is an elegant solution to this. Any expertise you can share would be greatly appreciated.

February 22, 2012 at 2:09 pm #366596

RossyP
@rossyp

If you can avoid it, I definitely would. I did in my first game and wish I hadn’t it, it was a massive pain. I used repeating backgrounds so I don’t have any advice on that aspect.

From memory, I think I checked if the player was near to an edge of the world – if they were, I’d move the sprite of anything that was close to opposite edge of the world by the appropriate amount so that it would appear correctly (I was using box2d so wouldn’t move the critter really, just the sprite location).

If anything crossed the edge I’d teleport it over to the appropriate map edge. That way you could fire and be shot at as normal. Until you use beam weapons or similar then it’s horrible.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.