Author Topic: NGUI Image Button Issue  (Read 3822 times)

LorDAlcatraZ

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
NGUI Image Button Issue
« on: January 29, 2014, 01:30:28 AM »
Hi guys,

I am using ImageButton to show visual button states. But when I hit play, the sprite in the UISprite component is replaced by the first sprite in the atlas. Everytime I changed the sprite, it got replaced with the first sprite. Is there an atlas issue or ImageButton problem? Please help in this regard. Thanks
« Last Edit: January 29, 2014, 01:43:07 AM by LorDAlcatraZ »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Image Button Issue
« Reply #1 on: January 29, 2014, 09:39:21 AM »
Double-check the sprite referenced under "Normal". It's likely not present in the atlas.

BehindTheStone

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 135
    • View Profile
Re: NGUI Image Button Issue
« Reply #2 on: January 29, 2014, 01:48:27 PM »
Yep, I have the same issue on the latest version. I can't tell when it happens, it's happening sometimes and sometimes not.
My Button has the UIButton and the UIImageButton-Scripts attached. I use the ImageButton for changing the normal and pressed state and the UIButton for disabling the button.
When the Button is hit it is disabled, after some time it's enabled again. Maybe that's the reason? The change from pressed to disabled is too fast?

(Also double-checked "Normal"-State. I removed the sprite from the atlas and added it again. Still happens.)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Image Button Issue
« Reply #3 on: January 29, 2014, 10:47:42 PM »
If you click on the actual sprite selection box under "Normal", does it have the sprite highlighted?

BehindTheStone

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 135
    • View Profile
Re: NGUI Image Button Issue
« Reply #4 on: January 30, 2014, 12:47:47 AM »
Yes, it does.

But I found actually a work-around for my problem. In the attached ImageButton-Script the "Disabled"-State is empty. As said above I wanted to use the "Disabled"-Behaviour of the UIButton-Script.
But I tried this: in the Disabled-State I selected the same Sprite from the "Normal" and "Hover"-State -> that way everything works and no weird "bugs" with the atlas. With both Scripts attached the Button changes it's color when disabled (UIButton-Script) and displays the correct sprite (same as in "Normal").

LorDAlcatraZ

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: NGUI Image Button Issue
« Reply #5 on: January 30, 2014, 01:18:39 AM »
Yeah. Sprite is present is present in the atlas. I override this problem by forcefully giving the normal and hover sprites in the UIImageButton. and now another issue is occuring. When I hit play, sprite gets resized and became smaller. Anyone know this issue?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Image Button Issue
« Reply #6 on: January 30, 2014, 09:47:14 AM »
@LorDAlcatraZ: UIImageButton script calls MakePixelPerfect() inside after swapping the sprites, which is what you're seeing. You can change the sprite type to be sliced, or you can comment out lines 59, 68 and 77 in UIImageButton. Or just make a copy of that script -- it's tiny.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Image Button Issue
« Reply #7 on: January 30, 2014, 09:59:09 AM »
I've modified the UIImageButton to ignore states that are not set, and added the "pixel snap" option that you can turn off if you don't want it to call MakePixelPerfect(). You will find it in the next update.

LorDAlcatraZ

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: NGUI Image Button Issue
« Reply #8 on: February 23, 2014, 02:24:53 PM »
Thank You very much Aren. My problem has been solved by doing this. (Y)