Author Topic: Update image button sprites  (Read 3029 times)

ivarhill

  • Guest
Update image button sprites
« on: January 30, 2013, 07:57:39 PM »
I have a script that changes the sprites of an image button if certain conditions are met - however, the new sprites do not show unless I actively mouseover/press the buttons in question. How can I refresh the image button in order to show the new sprites instantly?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Update image button sprites
« Reply #1 on: January 30, 2013, 08:11:38 PM »
Set them via spriteName, not via sprite.

ivarhill

  • Guest
Re: Update image button sprites
« Reply #2 on: January 30, 2013, 08:15:09 PM »
Hm - I'm setting them using the normalSprite, hoverSprite and pressedSprite properties of UIImageButton - isn't spriteName a UISprite property? Might be doing something wrong though...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Update image button sprites
« Reply #3 on: January 30, 2013, 08:21:24 PM »
Changing those won't update the current state of the background sprite -- you have to update it yourself via its spriteName property.

ivarhill

  • Guest
Re: Update image button sprites
« Reply #4 on: January 30, 2013, 08:21:52 PM »
Ah, I see - thank you :)

ivarhill

  • Guest
Re: Update image button sprites
« Reply #5 on: January 30, 2013, 08:30:59 PM »
I'm having a further issue with this - the sprite updates correctly now, but the scale is wrong - whenever I change the sprite through spriteName, the buttons are upscaled quite a bit and remains so until I mouse over them - any idea why this might be happening?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Update image button sprites
« Reply #6 on: January 30, 2013, 08:31:59 PM »
MakePixelPerfect() on it.

ivarhill

  • Guest
Re: Update image button sprites
« Reply #7 on: January 30, 2013, 08:34:31 PM »
Thanks, got it all working now :)