Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Tatanan on July 11, 2014, 11:37:03 AM

Title: Snap button is not giving exact pixels
Post by: Tatanan 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?
Title: Re: Snap button is not giving exact pixels
Post by: ArenMook 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.
Title: Re: Snap button is not giving exact pixels
Post by: Tatanan 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:
Thank you.
Title: Re: Snap button is not giving exact pixels
Post by: ArenMook 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.