Author Topic: Why can't I make a sprite with width 1 ?  (Read 8774 times)

ntopia

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 0
  • Posts: 15
    • View Profile
Why can't I make a sprite with width 1 ?
« on: April 11, 2014, 07:36:40 AM »
Why 'UIWidget.minWidth' == 2 ???

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Why can't I make a sprite with width 1 ?
« Reply #1 on: April 11, 2014, 07:52:16 AM »
For the sake of centering things evenly the dimensions should be dividable by two so you never get half-pixel positions.

ntopia

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: Why can't I make a sprite with width 1 ?
« Reply #2 on: April 11, 2014, 08:01:29 AM »
Thank you!
Then..
For drawing a sprite with width 1, what should I do?

When I make an atlas from img with width 1, NGUI makes sprite's width to 2 automatically.
So the result sprite in game is stretched and its width is 2.

Sorry for my poor english.

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Re: Why can't I make a sprite with width 1 ?
« Reply #3 on: April 11, 2014, 02:03:52 PM »
Question: How can one tell that a sprite with size 2x2 is stretched? :D

ntopia

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: Why can't I make a sprite with width 1 ?
« Reply #4 on: April 11, 2014, 11:50:08 PM »
Question: How can one tell that a sprite with size 2x2 is stretched? :D

The original img is a vertical bar with size 1x100.
I make an atlas from that img.
And make a sprite by using that atlas.

In result, a stretched vertical bar is printed with size 2x100.

The original img : 1x100 pixels showing
In game : 2x100 pixels showing ( with stretched )

So, I can tell that it is stretched.

Thank you!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Why can't I make a sprite with width 1 ?
« Reply #5 on: April 12, 2014, 04:53:27 AM »
NGUI adds 1 pixel of padding anyway if the dimensions are odd (not dividable by two). In your case you should do that by editing the sprite and giving it some padding -- 1 pixel vertically will be enough.

ntopia

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: Why can't I make a sprite with width 1 ?
« Reply #6 on: April 17, 2014, 06:52:22 AM »
Sorry for posting again.

But how about Tiled sprite?

I want to draw a line like this.


So I made a 3x1 img that one pixel is gray pixel and other 2 pixels are empty pixel.
And I made an atlas from that img.
After making an atlas, it converted to 1x2 img with right-border 2. (I don't understand it first)
And I printed it by tiled sprite and nothing was printed.

After that, I remembered your answer. So I added a 1 pixel to bottom-border of that img.
But it was same. Nothing was changed.

Am I going to wrong way?

ntopia

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: Why can't I make a sprite with width 1 ?
« Reply #7 on: April 17, 2014, 07:06:02 AM »
I asked a question about Tiled sprite 1 year ago.
http://www.tasharen.com/forum/index.php?topic=4190

I think that my question in this thread shows a necessary of padding in Tiled sprite.

Thank you!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Why can't I make a sprite with width 1 ?
« Reply #8 on: April 17, 2014, 11:27:12 AM »
It's not a good idea to use such tiny sprites. NGUI has to create 2 triangles for every repeat of the image. Use a larger sprite.

Also when adding the sprite to the atlas there is the "Trim Alpha" option. Uncheck it if you don't want it trimmed.