Author Topic: Pixel Perfect broken  (Read 3005 times)

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Pixel Perfect broken
« on: January 29, 2013, 10:25:57 AM »
Hi !

Long time no see :)

Just to say that with the new version, the pixel perfect is broken, if I take a UILabel and keep pressing the Make Pixel Perfect button, it will go down of 1px at every press of the button.

So if you're like mean, and doing a lot of Alt+Shift+P to make everything pixel perfect, your hole UI will go down... :(


It happens with this hierarchy :
#2D UI# (0, 0, 0) <- position
  Camera (0, 0, 0)
    Anchor (0, 0, 0)
      Menu (0, 0, 0)
        MenuGame (0, 0, 0)
          InfosRight (512, 310, 0) (no script attached to this GameObject)
            LabelCoinCount (-63, -30.5) <- this one keeps going down with each press
            Sprite (common_coin_small) <- this one does not move
« Last Edit: January 29, 2013, 10:28:36 AM by nah0y »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Pixel Perfect broken
« Reply #1 on: January 29, 2013, 05:36:26 PM »
What's the font's size?

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: Pixel Perfect broken
« Reply #2 on: January 30, 2013, 03:44:25 AM »
It's GillBold40, the scale is 47, 47, 1

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: Pixel Perfect broken
« Reply #3 on: February 14, 2013, 08:03:43 AM »
I'm still having this problem on some of my fonts :(

Your old code :
  1. Vector3 pos = cachedTransform.localPosition;
  2. pos.x = Mathf.FloorToInt(pos.x / pixelSize);
  3. pos.y = Mathf.CeilToInt(pos.y / pixelSize);
  4. pos.z = Mathf.RoundToInt(pos.z);
  5.  

The new one
  1. Vector3 pos = cachedTransform.localPosition;
  2. pos.x = (Mathf.CeilToInt(pos.x / pixelSize * 4f) >> 2);
  3. pos.y = (Mathf.CeilToInt(pos.y / pixelSize * 4f) >> 2);
  4. pos.z = Mathf.RoundToInt(pos.z);
  5.  

I don't really know what's going on, and why only in certain cases it add -1 every call to MakePixelPerfect :/
« Last Edit: February 14, 2013, 08:16:33 AM by nah0y »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Pixel Perfect broken
« Reply #4 on: February 14, 2013, 01:52:14 PM »
Try changing
  1. if ((y % 2 == 1) && (pivot == Pivot.Left || pivot == Pivot.Center || pivot == Pivot.Right)) pos.y -= 0.5f;
to
  1. if ((y % 2 == 1) && (pivot == Pivot.Left || pivot == Pivot.Center || pivot == Pivot.Right)) pos.y += 0.5f;

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: Pixel Perfect broken
« Reply #5 on: February 18, 2013, 03:58:12 AM »
Seems to be working thx !

I should not touch the one in the MakePositionPerfect method ?