There seems to be a lot of posts about endlessly scrolling backgrounds on one axis, but not much for a 2-axis solution. I'm trying to come up with a way to scroll terrain on both the X and Y axesAs Josh Petrie suggested, similarI'm posting my approach as an answer to how Google Maps or Apple Maps workssee if anyone can improve on your phone. This is a game with a top-down viewit.
More details of my current approach are described in a Stack Overflow post where I encountered a technical issue: http://stackoverflow.com/questions/44048257/physics-velocity-causes-parent-to-separate-from-childGame Requirements:
Basically, I'm applying the terrain texture tocreating a physics object2D game for iOS using SpriteKit and letting the user pan the objectSwift, but this paradigm could work for any touch-screen platform. I use the linear damping physics property to easily achieveThe game involves a smooth scrolling effect. My plan is createplayer sprite exploring an infinite field of outer space from a few terrain tiles and repeat them endlessly to cover the screentop-down 2D perspective. When the player pansThey drag their finger on the screen, the entire terrain object (which holds all the tiles) moves, creating the illusion that to move with scrolling behavior similar to panning a map in the player's sprite is movingGoogle Maps or Apple Maps apps.
WhenThe player should be able to scroll in any direction along the edgeX and Y axes indefinitely. The texture of the 2D space terrain object gets too close to the screen, I add more tiles offscreen so that we never see any gaps in the tile gridcould be generated and drawn programmatically. WhenOr it could take a tile gets too far from the centerlimited number of the screen, we delete the tiletextures made by an artist and recycle those images repeatedly to save memoryproduce the endless terrain.
Although, using a physics bodyPlanets and other objects will be added to hold the tiles lets me take advantage of the automatic scrolling behaviormap, its proving awkward to work with in other ways. I'm thinkingso there will have to go backbe a way to add these into the drawing board and try a different approachterrain as well. There are a number of ways IInitially, these objects can image to do thisappear at random, but nonewith a frequency that feels natural (i.e. you can't have too many planets or too few). Later, the location of planets will need to be retained so the player can revisit them seem good. I'm newSo a mapping system will have to game programmingbe implemented eventually, and wondering how other people would approach this problemthat data stored in memory. For now, that is not necessary but a solution that future-proofs against that necessity is preferred.