Search Unity

Unity 2d platformer game background [Help Urgent Please]

Discussion in 'Game Design' started by WirealTalha, Jul 31, 2019.

  1. WirealTalha

    WirealTalha

    Joined:
    Jul 19, 2018
    Posts:
    142
    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?
     
    jbb1979 likes this.
  2. NoctisShadowzel

    NoctisShadowzel

    Joined:
    Dec 27, 2018
    Posts:
    57
    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. https://forum.unity.com/threads/how-to-give-falling-effect-to-this-level-better.718319/#post-4803599 here I posted a little video of my second infinitely falling level designs bg. Hope it helps!
     
    jbb1979 likes this.
  3. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,639
    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.
     
    jbb1979 likes this.
  4. WirealTalha

    WirealTalha

    Joined:
    Jul 19, 2018
    Posts:
    142
    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
     
    jbb1979 likes this.
  5. WirealTalha

    WirealTalha

    Joined:
    Jul 19, 2018
    Posts:
    142
    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?).
     
    jbb1979 likes this.
  6. WirealTalha

    WirealTalha

    Joined:
    Jul 19, 2018
    Posts:
    142
    thanks mate. But i need advice on how to do it in a way thats more memory efficient.
     
    jbb1979 likes this.
  7. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,639
    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.
     
    jbb1979 and WirealTalha like this.
  8. WirealTalha

    WirealTalha

    Joined:
    Jul 19, 2018
    Posts:
    142
    Thanks so much. This helped alot.
     
    jbb1979 likes this.
  9. WirealTalha

    WirealTalha

    Joined:
    Jul 19, 2018
    Posts:
    142
    @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?
     
    jbb1979 likes this.