Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

What's the most optimal way to animate a BG?

Discussion in '2D' started by gorotoro, Jul 4, 2014.

  1. gorotoro

    gorotoro

    Joined:
    Nov 14, 2013
    Posts:
    10
    Hi all,

    The game I'm working on is in 2D, and it's a fixed camera. No scrolling, no parallax, nothing like that, just a guy in the center of the screen with a background behind him. (

    Just an FYI: I'm not a developer, have little knowledge of coding/scripting, and plan on completing this game using PlayMaker!)

    The background consists of 3 elements:

    - the Sky (picture the MAC OS "beach ball" as a sky: http://nanofunk.net/wp-content/uploads/2013/11/doom.jpg)
    - the clouds
    - the twinkling stars

    What I'd like the finished product to look like:

    - the Sky "pinwheel" spins slowly. Makes a complete revolution every 4 seconds.
    - the clouds scroll across the sky, looping every (x) seconds
    - the twinkling stars twinkle in an offset loop (they don't twinkle in unison)

    What I've done so far:
    - I imported the Sky sprite, and just used the animator to rotate on the Z axis, 359 degrees over 4 seconds at 30fps. So far it works fine, but the character isn't animating on the screen, and there's no interactivity, so I'm not sure what kind of hit the game will take when everything is in.

    What I'm planning on doing (with little knowledge of best practices):
    - spin the sky sprite using the animator
    - create cloud assets (3-4 different ones, w/ a total of up to 10 on screen at once), and scroll them across the sky, using the animator
    - create a single star sprite animation, and place instances all over the BG


    My main concern: What is the best way to get all of the elements described above to animate the way I want them without dragging the app to its knees? Am I on the right track with what I detailed above, or is there a better, more optimal way to do this?

    Thanks in advance!
     
  2. Rutenis

    Rutenis

    Joined:
    Aug 7, 2013
    Posts:
    297

    First of all, to rotate an object just write a simple script in C#:

    public float Speed;

    transform.Rotate(Vector3.forward * Speed * Time.deltaTime);


    To move clouds:

    public float MoveSpeed;

    transform.Translate(Vector3.right * Speed * Time.deltaTime);


    To spawn clouds, take an empty gameObject and place it where you want your clouds to spawn:

    public Transform clouds;

    IEnumerator CloudSpawn()
    {
    while(true)
    {
    yield return new WaitForSeconds(5);
    Instantiate(Clouds. transform.position, transform.rotation);
    }
    }

    void Start()
    {
    Start Coroutine(CloudSpawn());
    }



    If you need something more, just tell me. :)
     
    gorotoro likes this.
  3. gorotoro

    gorotoro

    Joined:
    Nov 14, 2013
    Posts:
    10
    Haha, thanks Rutenis. I figured a script was probably the *best* way to this, I should've phrased my question "most optimal way for an artist."

    :)
     
    Rutenis likes this.