Author Topic: Snap button is not giving exact pixels  (Read 3971 times)

Tatanan

  • Jr. Member
  • **
  • Thank You
  • -Given: 11
  • -Receive: 0
  • Posts: 81
    • View Profile
    • Casual Arena
Snap button is not giving exact pixels
« on: July 11, 2014, 11:37:03 AM »
When I use this button it sometimes gives me not the exact pixels of the sprite
If my sprites (png) is 110x107 it gives me 110x108.

If, moreover, I have used a unified anchor then sometimes I can't even fix it, ie, it's like the anchor forces you the pixels somehow.

How should I proceed?
Game developer on Casual Arena.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Snap button is not giving exact pixels
« Reply #1 on: July 11, 2014, 08:46:53 PM »
NGUI doesn't use odd sprite dimensions. It makes them even. So your 107 becomes 108, with an extra 1 pixel of padding added in so that it can be positioned properly. Think about it, centered widget with the width of 107... this means it's 107 / 2 = 53.5 pixels on each side. That obviously doesn't align with on-screen pixels, no way to make it pixel perfect. 108/2=54, aligns perfectly.

Tatanan

  • Jr. Member
  • **
  • Thank You
  • -Given: 11
  • -Receive: 0
  • Posts: 81
    • View Profile
    • Casual Arena
Re: Snap button is not giving exact pixels
« Reply #2 on: July 12, 2014, 05:56:43 AM »
I need to understand this a bit better to know to proceed.
Let me some more questions, please:
  • Is there any tutorial explaining that in details?
  • If I have a png of 35x45, are you meaning NGUI will deform it to something even? If so, wouldn't it appear uglier?
  • Should I employ only pngs of even x even dimensions?
  • If I remove the unified anchors, sometimes it does let me use odd pixels dimensions. Is there any reason I don't know?
Thank you.
Game developer on Casual Arena.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Snap button is not giving exact pixels
« Reply #3 on: July 12, 2014, 04:29:01 PM »
NGUI won't "deform" it. It will simply add 1 pixel padding to make dimensions even so that it aligns with pixels properly. If you place your sprite in a bottom-left corner of your screen with a bottom-left pivot, visibly it will extend the amount of pixels you'd expect -- 35x45. However the bounds of the sprite will extend to 36x46. To re-iterate: this is only for bounds of the sprite. Visibly your widget will extend the amount of pixels you would expect.

You should always rely on NGUI making the decision for you. MakePixelPerfect() on the sprite will snap it to proper size needed to draw the sprite crisply.

You don't need to use PNGs that are using even dimensions, but if you don't want there to be occasional 1 pixel padding, you should.