Author Topic: Why does UIImageButton force MakePixelPerfect on state change?  (Read 1704 times)

drjeats

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 13
    • View Profile
As we were laying out UI, we found that on Play, UIImageButton would resize Simple sprites back to what their actual pixel size.

Investigation led me to this thread and explanation from ArenMook:

You didn't mention using an image button. Yes, image button forcefully changes the size of your sprite to make it pixel-perfect when it changes sprites -- and this is the intended behaviour. You shouldn't stretch simple sprites, it just causes them to look blurry and distorted. Consider using a sliced sprite instead.

That makes sense, blurry sprites make me sad. But in this case we're actually reusing a larger sprite and scaling it down to fit another part of the UI. Seems pointless to make a small version for just a few use cases when the full-sized version is being used in other parts of the same UI. After looking into the UIImageButton and UISprite source I saw and remembered that a MakePixelPerfect call on a simple sprite sizes it back up to the actual pixel imensions of the image.

This isn't a big deal since we've got two workarounds:

  • Render as a Sliced sprite
  • Parent the sprite to an otherwise-empty GameObject and scale that parent

But this was driving our artist crazy for a good half an hour since this behavior is a bit of a surprise. It's pointless attempting to discourage scaling simple sprites because it's trivial to circumvent, and I'm not convinced that you can characterize the opposite use case--scaling down and reusing larger sprites--as an objectively bad or suboptimal use case. Are there deeper reasons for requiring a MakePixelPerfect call on every image button state change other than to discourage upscaling images?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Why does UIImageButton force MakePixelPerfect on state change?
« Reply #1 on: August 27, 2013, 12:54:41 PM »
It's intentional in case you make one sprite bigger. For example a highlighted sprite having frizzy edges around it.

And yes if you dont want it to be doing it just change the sprite type to sliced.