Author Topic: Missaligned oddsized sprites/textures  (Read 5579 times)

glequeux

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Missaligned oddsized sprites/textures
« on: November 29, 2013, 05:07:09 AM »
Hi,
I have a problem with oddsized sprite alignment.
There is a 1 pixel error when aligned to left or top.
I made a test scene with the 28 nov revision 24ac697 :
- 2D UI, removed the half pixel offset, a 17x17 Texture, point filtering, aligned right and top, position 0,0,0.
The texture is clearly not aligned to the axis, there is a 1 texel error :(
I have the same problem with sprites.

G.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Missaligned oddsized sprites/textures
« Reply #1 on: November 29, 2013, 09:02:56 AM »
This is intentional. NGUI adds 1 pixel to make the dimensions of the sprite even at all times for positioning purposes. The actual drawn image is your original size, but for positioning purposes an extra pixel of padding gets added.

glequeux

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Missaligned oddsized sprites/textures
« Reply #2 on: December 02, 2013, 04:45:45 AM »
Well it's really problematic if you want to join 2 sprites at the center like that :

As a programmer, I understand you did that because you don't want to center an oddsized sprite on a evensized panel. But, as a user in this case, there is no reason to have this transparent line between my 2 sprites.
Imagine you have a bunch of odd/even sprite you want to align right, they'll all look scrambled!
How am I supposed to programmatically chain sprites if the size I get is the not the real size of my sprite?
I feel that changing the size of all oddsized sprites is not the right way to deal with this problem :(
Maybe you should add a halfpixel only when centering request results in a halfpixel ? (ie when the pivot is set to center)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Missaligned oddsized sprites/textures
« Reply #3 on: December 02, 2013, 09:08:57 AM »
Then the visible image will change as you change the pivot point, so that too is not ideal.

You can simply have source images with dimensions dividable by two, or just edit the sprite and give it a 1 pixel padding on the left, thus making your dimensions even.

glequeux

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Missaligned oddsized sprites/textures
« Reply #4 on: December 02, 2013, 10:43:16 AM »
I don't see why the visible image would change?
Without changing the size of a sprite, I see 3 options, let's see what can happen for a 9 pixels width sprite,topleft, (0,0) :
A The pivot of a sprite is always an int
Then when I press pivotcenter, the pivot is 5 (rounding of 4.5) and x of the sprite is 5, rotations may be weird (but no more that the current implementation).
B The pivot of a sprite can be 0.5
Then the position of the pivot is now 4.5 and x too. Then the "pixelperfect" scripts must be aware that pixelperfect doesn't mean all coord have to be int.
C The pivot of a sprite is a float, the user may lose pixelperfect when centering
Same as before, when I press center, the pivot is 4.5, the position too.

Now if I put theses sprites on an anchor center and reset x to 0.
A: nothing change, the sprite is a bit offcenter to the left.
B: the mesh of the sprite must be "pixelperfected" during the fill
C: the sprite is blurry (Unless I press MakePixelPerfect which will set x to -0.5)

I'm aware this oddsized sprite is a big problem and theses solution might not be the best. I feel that the current implementation is a bit worth because changing the sprite size creates a lot of troubles. If you say that the best solution is "don't use oddsized sprites", IMHO it's the sign that the current implementation can be improved.