2D Space Shooter: Scrolling Background

I wanted to write up a quick article on how I achieved the scrolling background on my 2D Space Shooter game. I’ve checked out some tutorials on YouTube and I couldnt find one shorter than 20 minutes. This is an incredibly easy task, and shouldnt take 20 minutes to complete. Lets go!

This is the goal.

SO all I did was replace the sprite on the background I set up before. Then Added a script to the game object.

Here All I’m doing is saying the game object needs to move down at whatever speed I want. (I added a serializefield attribute to the speed variable as well as the original position variable.)

If the y position of this game object is greater than 4.4 and hasSpawned is false then Im going to instantiate the background prefab, at the original position location. As you can see here in the inspector I just found the point at which the top of the image left the bottom of the screen. Then set hasSpawned to true. If its below the screen, destroy it.

Later on I’ll add some conditions that change the background image completely/fades in a new background image. I just wanted to knock out this commonly used feature the easiest and most straightforward way I could. Hopefully you find this helpful! :)



Father Game Developer Music Composer Sound Designer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store