How to manage large backgrounds in scenes?

Hi everyone!

I am testing out what I have learned with the 2D game dev course from gamedev.tv, and am currently developing my first mini game. :slight_smile:

It’s about a small girl who is riding the mountain by ski and by bike to meet her grandparents.
It will be about beautiful landscapes and magnificent backgrounds, from green valleys to snowy mountain.

How should I manage/setup all the backgrounds and environment in my game?
I plan to have just 2 scenes that are rather long in distance. One scene to go up the mountain, a small break in a mountain hut as a cutscene, and one scene to go down the mountain.

Should I simply lay out all backgrounds in each scene and activate / deactivate them depending on camera’s position?
I plan to use a parallax effect with the different backgrounds as well to create a effect of depth.

Thank you :smiley:

Hi,

It’s great to see that you are developing your own game. Your theme sounds cute. :slight_smile:

Regarding the backgrounds, you don’t have to disable/enable them based on the camera position. The camera renders only what is inside its viewport.

However, depending on the number of backgrounds you want to display, it could be a good idea to have only 2 or 3 SpriteRenderers to which you assign your background images at runtime. For a few images, you create one SpriteRenderer per image. If you have hundreds, use as few SpriteRenders as possible.

The best would be if you start simple. Try to display your background images first without the parallex effect or any other fancy effects. Once that works, you could add more complexity to your game.

Also please feel free to ask our helpful community of students for advice over on our Discord chat server.

Good luck! :slight_smile:


See also:

Hi Nina,

thank you for your answer!
But I am not sure I understood it correctly :sweat_smile:

Let’s start simple and say I have three backgrounds:
-1/ with sky and clouds,
-2/ with a distant mountain outline
-3/ with a closer mountain with more detail on it

I should have 3 background game objects in the scene, correct?
The background 1 will not move a lot because it is very distant and I think that one image is enough for the whole scene.
The background 2 will move a bit faster, but I believe one simple image will not be enough for the whole scene and I will need to export the whole canvas from photoshop in a few images.
The background 3 will move way faster, (but not as fast as the player itself because parallax). I will export it from probably a few canvas from photoshop. (From mountain top to valley).

For background 2 and 3, should I update the sprite renderer on them depending on player position with the different exported images? Or should I replace them with new background game objects?

I hope my questions make sense :sweat_smile:

Thank you!

Your description sounds as if you need three different SpriteRenderers.

For background 2 and 3, should I update the sprite renderer on them depending on player position with the different exported images? Or should I replace them with new background game objects?

That depends on your idea. I would suggest to make your idea with the 3 backgrounds work. Then try to change one via code to see what happens in your game. Once you see a problem, try to solve it. Don’t try to solve theoretical problems before you even have a background in your game. Otherwise, you might end up planning things forever without ever seeing anything.

Privacy & Terms