I'm building a 2D game engine that uses tilesets to build levels. I recently added functionality to handle wraparounds (ie. where the right edge of the map connects to the left edge.) The engine scrolls the map to follow the character around, remaining centered on the player whenever possible.
I implemented wraparound as follows:
The map engine has a Viewport object, which has a bounding rect and can test each tile to see if the tile is contained within the viewport. When the screen coordinates are such that wraparound is needed, the viewport can set up sub-viewport objects that display different parts of the coordinate space, and place them side by side.
Each frame, I test the tiles on the map against the viewport to see if they can render. Each tile object has a
viewport property designating which viewport it's rendering into. In the case of a composite viewport, this will delegate the test to each sub-view in turn, and on the first match, set the tile's viewport object and break the loop.
This works just fine in practice, until I hit one specific edge case: When the map is the minimum size, which is exactly the size of the screen, while trying to scroll, the tiles along the edge will be in the area of both viewports at once until the scroll completes the full width of that tile, which causes it to render on one edge and the other edge to show blank space for a moment.
I could resolve this by giving each tile a list of viewports instead of a single one, but that would significantly increase the complexity of my rendering, which I want to keep as fast and simple as possible, just to deal with a minor edge case.
Does anyone know of an elegant way to resolve this issue?