Author Topic: Sprites changing to original after mouse off  (Read 5434 times)

matt1

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 28
    • View Profile
Sprites changing to original after mouse off
« on: January 22, 2015, 05:24:40 PM »
Hi,

I've recently upgraded to NGUI after a long period of procrastination, I'm really love it so far!

One issue I've come across is creating a button via scripting, setting its spritename. At first it works, but as soon as I mouse over and off the sprite it will change back to the sprite that it was referenced to. I've tried changing all the fields but it always reverts. I've attached some images below. Any help would be great!

Thanks

« Last Edit: January 22, 2015, 06:20:03 PM by matt1 »

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Sprites changing to original after mouse off
« Reply #1 on: January 22, 2015, 06:42:38 PM »
It's a flaw in how UIButton works. It caches the "normal" sprite on start, so if you set the sprite to something else at run time, it will revert to its cached normal sprite when you mouseover and hover out.

I'm not sure if you can change the normal sprite from outside, but you can make it not cache at start and cache when it needs to change instead, then it should be fine.

Alternatively, don't use UIButton, but a combination of UIButtonColor and UIEventTrigger instead.

matt1

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: Sprites changing to original after mouse off
« Reply #2 on: January 22, 2015, 07:07:02 PM »
Thanks for the answer!

Sorry, but how does one cache?

Thanks again

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprites changing to original after mouse off
« Reply #3 on: January 23, 2015, 09:33:10 PM »
You shouldn't be directly changing the sprite that's referenced by a button. If you want to change the button's normal state sprite, then do just that -- via UIButton.normalSprite.