Author Topic: Flickering when swapping UISliders  (Read 5394 times)

filippopotamus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 31
    • View Profile
Flickering when swapping UISliders
« on: August 04, 2012, 04:21:47 PM »
I have 5 different sliders on top of each other. Only one is active at a time. when I reach a certain value on the slider, I swap to a different slider and now the new slider is the one active and I deactivate the other one. However, when the swap occurs, most of the time there is a flicker as it swaps. As if there is a frame where there is no slider and then the other one appears. Initially I had it so I disabled the current slider fisrt and then enabled the new one, which I thought it was the problem. But when enabling the new one first and then disabling the old one didn't fix it either. I also tried making the Depth of the new one higher than the current, enabling it, then disabling the older and that didn't work either. Any tips? Here is the code as it stands:

  1.         void SwapFace(int targetFace){
  2.                
  3.                 switch(targetFace){
  4.                         case 1:
  5.                                 NGUITools.SetActive(face1.gameObject, true);
  6.                                 _activeSlider = face1;
  7.                                 break;
  8.                         case 2:
  9.                                 NGUITools.SetActive(face2.gameObject, true);
  10.                                 _activeSlider = face2;
  11.                                 break;
  12.                         case 3:
  13.                                 NGUITools.SetActive(face3.gameObject, true);
  14.                                 _activeSlider = face3;
  15.                                 break;
  16.                         case 4:
  17.                                 NGUITools.SetActive(face4.gameObject, true);
  18.                                 _activeSlider = face4;
  19.                                 break;
  20.                         case 5:
  21.                                 NGUITools.SetActive(face5.gameObject, true);
  22.                                 _activeSlider = null;
  23.                                 break;
  24.                         case 6:
  25.                                 NGUITools.SetActive(face6.gameObject, true);
  26.                                 _activeSlider = null;
  27.                                 break;
  28.                         default:
  29.                                 Debug.Log("[RagemeterManager]: Invalid target rage level!");
  30.                                 break;
  31.                 };
  32.                
  33.                 DisableFacesExcept(targetFace);
  34.         }
  35.        
  36.         void DisableFacesExcept(int i){
  37.                 if(i != 1) NGUITools.SetActive(face1.gameObject, false);
  38.                 if(i != 2) NGUITools.SetActive(face2.gameObject, false);
  39.                 if(i != 3) NGUITools.SetActive(face3.gameObject, false);
  40.                 if(i != 4) NGUITools.SetActive(face4.gameObject, false);
  41.                 if(i != 5) NGUITools.SetActive(face5.gameObject, false);
  42.                 if(i != 6) NGUITools.SetActive(face6.gameObject, false);
  43.         }

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: Flickering when swapping UISliders
« Reply #1 on: August 05, 2012, 02:48:27 AM »
Any reason why you don't just use one slider and dynamically change its target & constraints as needed?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Flickering when swapping UISliders
« Reply #2 on: August 05, 2012, 09:08:05 AM »
I'd also suggest doing what JRoch said -- just use one slider. However, if you wish to use several, you can call UIPanel.Refresh() on the slider's panel as soon as you enable it and there won't be a flicker.

http://www.tasharen.com/forum/index.php?topic=841.msg6343#msg6343

filippopotamus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 31
    • View Profile
Re: Flickering when swapping UISliders
« Reply #3 on: August 05, 2012, 06:22:45 PM »
Actually there is no reason at all I didn't use the same slider and dynamically changed it's foreground/background. Must have been one of those late night coding brain farts. Thanks!

I did ArenMooks solution of calling Refresh on the panel for now and that seems to work, but I wrote it down JRoch's solution for when I start optimizing things! Thanks guys! :)