Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Any tricks to stretch a UI Sprite with a frame?

Discussion in 'UGUI & TextMesh Pro' started by Shack_Man, Apr 16, 2020.

  1. Shack_Man

    Shack_Man

    Joined:
    Jun 7, 2017
    Posts:
    372
    Say I have a panel that uses a 50x50 sprite as a background, that sprite has a frame of 5px on all side. If I stretch the panel to something like 150x50, the frame starts to look weird, since the sides no become wider while the top and bottom stay 5px. Is there any trick for keeping the frame consistent?
     
  2. giantkilleroverunity3d

    giantkilleroverunity3d

    Joined:
    Feb 28, 2014
    Posts:
    383
    Correct, the frame stretches all components inside. ...from what I have experienced.
    Try modifying the x axis in the inspector scale. I have run into this and have had to adapt many different corrections to this. I finally came up with panel with a solid color image. Play with that for a while and let it sit in game operation till you are satisfied with sizing. Then build the image to that size. It seems backward but it is what it is. I have used GIMP for this creation purpose because of the pixel sizing at the first stage of creation. I mention this mundantiny because its common practice to draw at the beginning so one can 'See' the glory in all its presence. But then adjustments cause display problems. Sorry to give you the backward answer but initially working with solid panels will definately solve your headaches in the future.
    In fact, thank you for this post. My pop up panels have no borders or graphics, just solid color backdrops. I thought I was done with my game but now I can go back and add this suggestion.
    To all others: If for some reason this advice is incorrect I also love to hear a better solution.
     
    Shack_Man likes this.
  3. Shack_Man

    Shack_Man

    Joined:
    Jun 7, 2017
    Posts:
    372
    I used to do that as well, but now I have some panels with content fitters, so their size changes ingame to quite a wide range. I wish there were an option to do something like "stretch but preserve top and bottom 20%".
     
  4. giantkilleroverunity3d

    giantkilleroverunity3d

    Joined:
    Feb 28, 2014
    Posts:
    383
    Ouch! Content fitter. Oh, the nightmare that I see. I haven't even started down that rabbit hole yet. God forbid. I see a coding nightmare. Any empathy for my grief? Maybe assets in store? You could sell something.
     
  5. Shack_Man

    Shack_Man

    Joined:
    Jun 7, 2017
    Posts:
    372
    I can only think of making multiple copies of the image and using a mask to hide the middle part. I'll try to slap something together and post it, but probably only in a week or so, I have to wrap up a game.