# Scrolling World

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder

## Background

In order to further the endless runner game, we must first have the player run. In order to do this, rather than moving the player, we will instead move all of the other objects on the stage; making it appear as though he is moving forward. We can do this by using 2 images and when one goes off screen, we can place it on the right side of the screen.

## Experiment

### Getting Started

Continue from the previous project; we’ll be editing all of our files there. Enter into the GameScene directory of the project.

tariq-mahamid@codermerlin: cd ~/Experiences/ChangingScenes/Sources/ScenesShell/GameScene

## Scrolling Background

Enter the background file of your project in order to start creating the scrolling background.

In order to create the background, we must first initialize the correct variables:

```    let backgroundSpeed : Int
let parallaxBackgrounds : [Image]
var parallaxCurrentPoints : [Point]

init(backgroundSpeed: Int) {
guard let parallaxBackgroundURL = URL(string: "https://i.ibb.co/C09XGhG/1920x1080-1.png") else {
fatalError("Failed to create URL for parallaxBackground")
}
parallaxBackgrounds = [Image(sourceURL: parallaxBackgroundURL), Image(sourceURL: parallaxBackgroundURL)]
parallaxCurrentPoints = [Point(), Point()]
self.backgroundSpeed = backgroundSpeed

super.init(name:"Background")
}
```

## Exercises

Exercises
• Use the calculate function to move the background to the left and reset it when it goes off screen.
• Create an obstacle script that spawns 2 types of obstacles, one that is high that the player will have to duck under and one that is low and the player will have to jump over. These obstacles should reset to the right when off screen.