Author Topic: What can change the scale of a sprite?  (Read 2045 times)

zoombapup

  • Guest
What can change the scale of a sprite?
« on: July 31, 2013, 06:29:18 AM »
Hey all, new to NGUI, but I'm getting on OK with it so far. But I've got a bit of a weird case I hope someone can help me with.

I'm working on an inventory and the setup is pretty similar to the NGUI example, in that I've got a panel with collider and scale button script, plus two child sprites (one for background one for icon).

Anyway, my problem is that somehow the icon is being instantiated at the wrong scale. If I modify the scale of the template prefab for the background it works as expected, but if I do the same thing for the icon, it seems to have no effect at all. What's even weirder is that when I first instantiate the prefab the scale of the icon is different than when the panel is activated.

Is there any good place to stick a breakpoint to try and identify where the scale is being changed for the icons? What actually ends up determining what the scale of a sprite is??

Hope someone can shed some light here.

zoombapup

  • Guest
Re: What can change the scale of a sprite?
« Reply #1 on: July 31, 2013, 08:06:07 AM »
Hmm, looks like the call to makepixelperfect was effectively resizing the sprite. Guess I thought it would simply make the overall rectangle value integer sizes instead of actually sizing the sprite to some notional size value. Lesson learnt there.

dlewis

  • Guest
Re: What can change the scale of a sprite?
« Reply #2 on: July 31, 2013, 09:28:36 AM »
Make pixel perfect on a UISprite of type simple will change the scale to the pixel size. If the UISprite it of type sliced then it will make it whole numbers.

zoombapup

  • Guest
Re: What can change the scale of a sprite?
« Reply #3 on: July 31, 2013, 10:42:14 AM »
Thats what I expected to happen, but that is definitely NOT what I'm seeing. If I disable makepixelperfect in my cursor and other sprite calls, I get the right size (64x64) but if I don't call that, I get something else entirely (121x121 weirdly).

I'm guessing it gets the size from texture coordinates or something. But I really expected to just round to the nearest integer as you mention.

Weird huh?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: What can change the scale of a sprite?
« Reply #4 on: July 31, 2013, 12:35:16 PM »
If the original texture is 121x121, then that's what hitting Make Pixel Perfect will set the sprite to.