Author Topic: Correcting Half Pixel offset during editing  (Read 4731 times)

shinki

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Correcting Half Pixel offset during editing
« on: July 29, 2015, 06:51:30 AM »
Hi everyone,

I've recently butted up against an issue with my sprites straying from their handles, while running in the editor at least. (NGUI 3.9.0)

An old topic (http://www.tasharen.com/forum/index.php?topic=7057.0) suggests that this is due to the half pixel offset applied on the UIPanel. Low and behold, if I set mHalfPixelOffest to false, all of the sprites render in the right place.

I appreciate that this is a minor glitch, and may well never occur/be noticed in a published project, but it is making lining up and anchoring sprites a little difficult in our current project as they are all off by a pixel one way or another.

I was wondering if the code that detects whether to enable this offset (in UIPanel's Awake) could be improved to correctly detect this case where it clearly shouldn't be on but the current logic says it should. Unfortunately I don't know enough about this to correctly determine when it should be on. If anyone can help with a nice solution to this, rather than simply hacking it off, I would appreciate it!

Cheers!

Update:

Actually, upon further inspection, with the half pixel offset on or off, I'm still seeing some sprites straying from their handles in different directions. Wondering if there's another issue at play. (See attached image).
« Last Edit: July 29, 2015, 07:14:19 AM by shinki »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Correcting Half Pixel offset during editing
« Reply #1 on: July 31, 2015, 09:31:25 PM »
It's something else. Try it in the latest NGUI first (3.9.1)

shinki

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Correcting Half Pixel offset during editing
« Reply #2 on: August 05, 2015, 04:01:59 AM »
Having tested in a vanilla drop of NGUI 3.9.1 I'm still seeing the sprites stray from their handles. In this case it seems to be changed by resizing the game window (could be related to the other thread I opened, but not sure...).

Steps to see it:

- Import NGUI 3.9.1
- NGUI > Create 2D UI
- Set UIRoot to constrained height 720
- Create Panel under UI Root
- Create a Sprite under Panel (I used the Light sprite in Ngui Examples SciFi Atlas)
- Resize game window at aspect 16:9
- (In my images the sprite is 18x18 and positioned at x = 0, y = -172)

Attached images showing the different offset at certain game window sizes.

Cheers!


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Correcting Half Pixel offset during editing
« Reply #3 on: August 05, 2015, 09:23:21 AM »
Constrained UI = scaled pixels to begin with. The issue gets worse if your window's dimensions are not dividable by two as an additional "fake" offset is then used to maintain pixel crispness. Stick to one topic please.

mdeletrain

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 71
    • View Profile
Re: Correcting Half Pixel offset during editing
« Reply #4 on: August 05, 2015, 09:47:20 AM »
Indeed I saw the same problem as shinki recently. What happens is that sprites' bounding boxes are not aligned with their actual content in the scene view IF the game window is displayed.
And the offset is not a matter of 1 or 2 pixels, it can be as much as the whole sprite to be displayed.
I'll try to reproduce that on my side and send a screen capture...