Unity 2d platformer game background [Help Urgent Please]

So I am creating unity 2d game. Its a platformer game. With infinite scrolling background. The porblem is the background? what should we do about it? like creating one longgg background and make the camera move over it? or should we use a relatively smaller background and use prefabs

e.g the background is composite of two parts. background_ and foreground_. background_ is just colour. and foreground is the trees and stuff there are many themes for foreground ,like trees , mountains and beach etc, and ground holding them(trees).

which one is more memory efficient? what should i do? one very long or shorter with prefabs?

1 Like

I made two infinite falling levels for my projects. I used an entrance bg, 2 different designs for continous moving backgrounds, an a main static background that lights up at the start to give player effect of falling inside a tunnel. After entrance bg, other 2 moving bgs (as prefabs) gets spawned one after another, and disappears at a point where camera can’t see.
**PS. How to give "falling" effect to this level, better? ** here I posted a little video of my second infinitely falling level designs bg. Hope it helps!

1 Like

Use smaller parts.

If you have 8 objects next to each other that each have the same smaller texture (1024x1024), that texture is only in memory 1 time. If you have one big texture that’s the same size as 8 textures put together (8192x1024), then it going to take-up 8 times the memory for the same result. Remember also that graphics cards have limits on the maximum texture size that they can copy also.

Also if your background is all one piece than Unity will have to render the entire background each frame, whereas with small pieces, it only renders the pieces that are on the screen.

1 Like

Thanks for replying. this is good. So This would be your advice? to break up textures into smaller bits rather than using a full long background

1 Like

here is the actual thing and i need your view on it. So foreground_ is approx. 25% of the screen and background_ is just a colour gradient. in foreground there are a few components like (trees (different trees), ground, stones, bushes) what is the perfect solution here?

get all components of foreground, prefab them and then use prefabs in game? whats to do with background_? since its only a colour gradient? (i think use only one background_ that fits the camera size and use it for scrolling. right?).

1 Like

thanks mate. But i need advice on how to do it in a way thats more memory efficient.

1 Like

Pretty much.

With the foreground objects, use separate parts. Avoid having big areas of transparent pixels if you can help it. They still take time to render, even though you don’t see anything.

For the background, you could make a quad that’s about the size of the screen and make it a child of the camera. That way it will go where ever the camera goes.

2 Likes

Thanks so much. This helped alot.

1 Like

@kdgalla What about the components of Trees? i was thinking make a prefab made out of 3 components of trees. 3 different images make up one tree. then use that prefab but change the colours of the 3 images to get as many different combinations of trees? but in what size (pixels) should i be printing me sprites in? this has been confusing me since the start of my project. What size to fit 'em all? what size would look good on all devices from iphoneX to low end devices?

1 Like