Author Topic: Possible bug regarding hide/show sprite  (Read 4100 times)

damocles

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Possible bug regarding hide/show sprite
« on: March 07, 2013, 04:21:53 AM »
I think I've found a minor bug.  I have several UISprites that change position and drop in and out of active state regularly.  In some cases, a sprite may be hidden and shown (set inactive and then active) in the same frame (same update code block, no chance of this being across 2 frames).  When this happens, the sprite 'blinks'.  I think what is happening is that NGUI is registering the inactive state, and updates the sprite as invisible, but does not realize it has been reactivated in the same frame.  Then in the next frame NGUI sees it is visible and updates the mesh to show it.

This results in a very noticeable single frame where the sprite is invisible but should be visible,  creating a 'blink' effect.

I got around this by adding a method to UISprite:

  1. public void setDirty()
  2. {
  3.         mChanged = true;
  4. }

and calling this after I show the sprites.  This forces the rebuild in the same frame.

I haven't investigated deeply, but my guess would be that you are comparing a stored boolean somewhere against the active state of the UISprite game object, and so it takes two frames to register two changes.  That's just my wild guess though.

EDIT:  Update - It seems that setting mChanged to true does not fix this problem.  I think it was just a case that I did not see the blinks the last few times I tried, but I have seen them occur since I made this post.  So I'm open to suggestions on fixing this.
« Last Edit: March 07, 2013, 04:32:39 AM by damocles »

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Possible bug regarding hide/show sprite
« Reply #1 on: March 07, 2013, 05:02:01 AM »
Call Refresh() on your panel.

damocles

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: Possible bug regarding hide/show sprite
« Reply #2 on: March 10, 2013, 11:00:52 AM »
Thanks Nicki, I completely missed that method while hunting through UIPanel  :-[.  I would have thanked you sooner, but for some reason the forum didn't email me your reply.

For ArenMook, if he sees this:
During my experimentation, I discovered that moving the sprites off screen and then back on screen would work fine - no flicker.  It was only if you deactivate and reactive the sprites in the same frame you get the flicker.  Odd that movement would cause a rebuild of the panel, but deactivation/reactivation would not.  Might be worth investigating if you have some free time.


Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Possible bug regarding hide/show sprite
« Reply #3 on: March 10, 2013, 11:38:53 AM »
Activating a widget causes it to register with the panel to draw it, but it doesn't get drawn until the next update cycle, so you get that flicker.

Refresh forces a redraw this frame even though you're past the Update timing.