Author Topic: Fading in and out on scene change.  (Read 2519 times)

Diabolikal49

  • Guest
Fading in and out on scene change.
« on: December 03, 2013, 10:08:57 AM »
I have a large SlicedSprite which is being used as a fader. I have a coroutine which calls TweenColor.Begin for a set duration and then loads a new scene. This works perfectly.

My problem is trying to fade from black upon loading the new scene. I imagine this is an order of operations problem but I can't quite seem to grasp a solution, nor can I find an appropriate answer on the web. I am using a Singleton/dontdestroyonload pattern to keep the same instance of my entire UIRoot throughout the runtime of the game.

  1. IEnumerator FadeFromColourRoutine(Color colour)
  2. {
  3.         TweenColor.Begin(PanelFader, UIFadeTime, colour);
  4.         yield return new WaitForSeconds(UIFadeTime);
  5.         NGUITools.SetActive(PanelFader, false);
  6. }
  7.  
  8. public void FadeFromBlack()
  9. {
  10.         StartCoroutine("FadeFromColourRoutine", new Color(0,0,0,0));
  11. }
  12.  
  13. public void FadeToBlack()
  14. {
  15.         NGUITools.SetActive(PanelFader, true);
  16.         TweenColor.Begin(PanelFader, UIFadeTime, new Color(0,0,0,1));
  17. }

I have also tried to make sure that the level had been loaded before running the fading function.

  1. void OnLevelWasLoaded(int level){
  2.         if(level < 2){
  3.                 FadeFromBlack ();
  4.         }
  5. }

Any suggestions or pointers would be very appreciated. Thanks.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Fading in and out on scene change.
« Reply #1 on: December 03, 2013, 10:22:05 AM »
So what is actually happening?

Diabolikal49

  • Guest
Re: Fading in and out on scene change.
« Reply #2 on: December 03, 2013, 11:49:43 AM »
Apologies, not sure how I omitted that important detail...

The problem I had is that that fader panel works well with everything in the scene except other NGUI objects. On scene change, the Main Menu is visible straight away while the rest of the scene fades in from black. I would like everything to fade in at the same time.

I have the Fader set to a depth of 50 while everything else is on 0 or 1.

Of course, I could do similar fades with the Main Menu panel as well, but I had expected my fader panel to obscure everything.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Fading in and out on scene change.
« Reply #3 on: December 03, 2013, 08:57:24 PM »
Assuming you have two different UI hierarchies, you also have two different UI cameras, so what's drawn on top is going to be controlled by the camera's depth. You need to ensure that your fader UI is drawn using a camera that has a higher depth value.

Diabolikal49

  • Guest
Re: Fading in and out on scene change.
« Reply #4 on: December 04, 2013, 09:17:02 AM »


I have 1 UI hierarchy and 1 UI camera for it. My MainCamera does not render the UI and my UICamera only renders the UI. I don't normally have that UIRoot in the scene, it is loaded from Resources at runtime.

Diabolikal49

  • Guest
Re: Fading in and out on scene change.
« Reply #5 on: December 04, 2013, 09:42:26 AM »
The MainMenu panel has an anchor attached with a depth offset of 0. Would this affect the outcome?








ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Fading in and out on scene change.
« Reply #6 on: December 04, 2013, 05:08:36 PM »
Judging by your screenshots you are still using NGUI 2.X, which is no longer supported. Too many things have changed since the 2.X cycle.

Diabolikal49

  • Guest
Re: Fading in and out on scene change.
« Reply #7 on: December 04, 2013, 06:13:31 PM »
Ok, I shall update and see if it changes anything, thanks for taking the time to look at my issue though.