Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
updated tags
Link
Bumped by Community user
Changed the summary of my approach because I posted a detailed version of it as an answer.
Source Link

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.

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 axes, similar to how Google Maps or Apple Maps works on your phone. This is a game with a top-down view.

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-child

Basically, I'm applying the terrain texture to a physics object and letting the user pan the object. I use the linear damping physics property to easily achieve a smooth scrolling effect. My plan is create a few terrain tiles and repeat them endlessly to cover the screen. When the player pans the screen, the entire terrain object (which holds all the tiles) moves, creating the illusion that the player's sprite is moving.

When the edge of the terrain object gets too close to the screen, I add more tiles offscreen so that we never see any gaps in the tile grid. When a tile gets too far from the center of the screen, we delete the tile to save memory.

Although, using a physics body to hold the tiles lets me take advantage of the automatic scrolling behavior, its proving awkward to work with in other ways. I'm thinking to go back to the drawing board and try a different approach. There are a number of ways I can image to do this but none of them seem good. I'm new to game programming and wondering how other people would approach this problem.

There seems to be a lot of posts about endlessly scrolling backgrounds on one axis, but not much for a 2-axis solution. As Josh Petrie suggested, I'm posting my approach as an answer to see if anyone can improve on it.

Game Requirements:

I'm creating a 2D game for iOS using SpriteKit and Swift, but this paradigm could work for any touch-screen platform. The game involves a player sprite exploring an infinite field of outer space from a top-down 2D perspective. They drag their finger on the screen to move with scrolling behavior similar to panning a map in the Google Maps or Apple Maps apps.

The player should be able to scroll in any direction along the X and Y axes indefinitely. The texture of the 2D space terrain could be generated and drawn programmatically. Or it could take a limited number of textures made by an artist and recycle those images repeatedly to produce the endless terrain.

Planets and other objects will be added to the map, so there will have to be a way to add these into the terrain as well. Initially, these objects can appear at random, but with 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. So a mapping system will have to be implemented eventually, and that data stored in memory. For now, that is not necessary but a solution that future-proofs against that necessity is preferred.

Source Link

2D Infinite scrolling terrain on two axes

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 axes, similar to how Google Maps or Apple Maps works on your phone. This is a game with a top-down view.

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-child

Basically, I'm applying the terrain texture to a physics object and letting the user pan the object. I use the linear damping physics property to easily achieve a smooth scrolling effect. My plan is create a few terrain tiles and repeat them endlessly to cover the screen. When the player pans the screen, the entire terrain object (which holds all the tiles) moves, creating the illusion that the player's sprite is moving.

When the edge of the terrain object gets too close to the screen, I add more tiles offscreen so that we never see any gaps in the tile grid. When a tile gets too far from the center of the screen, we delete the tile to save memory.

Although, using a physics body to hold the tiles lets me take advantage of the automatic scrolling behavior, its proving awkward to work with in other ways. I'm thinking to go back to the drawing board and try a different approach. There are a number of ways I can image to do this but none of them seem good. I'm new to game programming and wondering how other people would approach this problem.