# Redistributing sprites in procedural generation according to player movement

I am making space arcade with procedurally generated background consisted of nebulas and stars sprites, which spawn on Awake() in certain borders around player.

Mobile phones have limited capacity so I want to redistribute sprites along the player's movement. E.G. if player reaches an empty area where is no sprites, I want sprites which farthest relatively to player to move in front of player. So player couldn't ever see an empty area. Notice that player can move in any direction in 2D space, not only up.

• If the player flies right far enough that all the sprites in their starting area reposition, then flies back left the same distance to get back to their starting point, do you need to rearrange the sprites to put them back exactly where they were for consistency? Or is it OK if the player can't step into the same river twice, as it were? – DMGregory Apr 5 '18 at 13:34
• It is better if the player can't step into the same river twice) – Nikita Demidenko Apr 6 '18 at 7:43

5. Add a new script to the invisible game object which implements the OnTriggerExit(Collider other) event. In that script, check if other is a background sprite, and if so move it to the opposite side of the screen by assigning a new vector to its transform.position. When your world origin (world-space coordinates 0:0:0) is always in the center of the screen, then you can simply flip it on all axis' with transform.position = -transform.position;. When your camera is moving, the math gets a bit more complicated. How complicated depends on your actual scene setup.