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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to change between sprites smoothly?

Discussion in '2D' started by circleline, Mar 13, 2015.

  1. circleline

    circleline

    Joined:
    Nov 29, 2014
    Posts:
    42
    For instance, I have 2 sprites the Square & Circle. I have the circle in my scene and if(1==1){change the circle to square}, How do i do it smoothly?
     
  2. Xelnath

    Xelnath

    Joined:
    Jan 31, 2015
    Posts:
    400
    Define "Smoothly"
     
  3. circleline

    circleline

    Joined:
    Nov 29, 2014
    Posts:
    42
    Umh like morphing
     
  4. Xelnath

    Xelnath

    Joined:
    Jan 31, 2015
    Posts:
    400
    Yeah, you can't do that with Sprite objects - you would need some complex vector morphing toolkit.
     
  5. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    A quick & easy solution that might work for your needs is to use fading in and out.

    When you want to do the morph place a second sprite at the same location with full transparency.

    So you can fade from the circle to the square by placing a square at the same location as the circle with its SpriteRenderer.color.a set to 0 so it is hidden fully transparent. Now you can start a little "morph" routine that decreases the value of the circle's SpriteRenderer.color.a and increases the value of the square's SpriteRenderer.color.a causing a sort of cross-fade effect where the circle fades out at exactly the same time the square fades in. If done at the right speed the may give you a workable morphing effect.

    I knocked out a little test of it. Here they appear on a black background and you will likely have a background scene which should help the illusion even more.

     
    Last edited: Mar 20, 2015
  6. circleline

    circleline

    Joined:
    Nov 29, 2014
    Posts:
    42
    Thanks!
     
  7. Xelnath

    Xelnath

    Joined:
    Jan 31, 2015
    Posts:
    400