Author Topic: Using UIStretch with a manual height UIRoot  (Read 12057 times)

GavinF

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Using UIStretch with a manual height UIRoot
« on: September 26, 2012, 08:27:56 PM »
I have a background image I am trying to scale to cover the entire screen.  I attach a UIStretch script to it, set the Style to 'Both' and leave the relative size at 1,1.  I have a UIRoot with a manual height set to 480 and automatic unchecked.  It works in that my background image always covers at least the extents of my game window, but unless I'm at a resolution of 320x480 the image seems to scale beyond the bounds of my game window.

When I switch the game window to use 640x960, the background image scales to what looks to be roughly double the size of the screen. The scaled size of the background image in inspector is 640x960 (which is what one would expect), but if I view the background image in the Scene window, it clearly extends beyond the widgets that I have anchored to the sides of the game window. 

This is ok in that it covers the entire screen, but when I try to use this stretched background as a Widget Container in a UIAnchor, my anchors end up being off-screen.  Same thing if I use my UIPanel parent as a UIPanel Container.

The reason I am trying to use a Widget or Panel container for my anchors is because of a sorting issue I am trying to fix in which I am using background sprites behind a dynamically loaded UITexture with more sprites layered on top (despite my best efforts to convince our artists that this would be problematic) but my sorting problem probably warrants creating a different post. 

My main question is, should the background be scaling beyond the bounds of my screen based on how I'm using the UIStretch script and my UIRoot? Is this a bug, or is this just how it is supposed to work?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Using UIStretch with a manual height UIRoot
« Reply #1 on: September 26, 2012, 08:32:44 PM »
What version of NGUI are you using? I just tried it on 2.2.1 in a clean scene and everything works as you'd expect. UIStretch on a sliced sprite always fills the screen regardless of manually set UIRoot value.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Using UIStretch with a manual height UIRoot
« Reply #2 on: September 26, 2012, 08:35:07 PM »
Also keep in mind UIAnchor currently only works if the anchored object has the same parent as what you're trying to anchor. Ie: if you're stretching the background to cover a label, both must have the same parent object. This limitation gets removed with the coming update I believe (Phil made that change).

GavinF

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Using UIStretch with a manual height UIRoot
« Reply #3 on: September 27, 2012, 12:30:38 PM »
It looks like we are on 2.1.4.  I'll give it another try after updating (though that might not be until next week).  Thanks for the info!  Explains some of what I've been seeing with my anchors.

jeldrez

  • Sr. Member
  • ****
  • Thank You
  • -Given: 8
  • -Receive: 4
  • Posts: 352
    • View Profile
Re: Using UIStretch with a manual height UIRoot
« Reply #4 on: January 09, 2013, 05:55:42 PM »
I have a similar issue, if I increase the 'Game' window starts showing blue background, I've the UIRoot on Automatic, this should adjust to any size?

Thanks in advance.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Using UIStretch with a manual height UIRoot
« Reply #5 on: January 10, 2013, 01:44:10 PM »
NGUI never skews the aspect ratio of your UI, so if you change the aspect ratio of our game window, you will see less or more of your UI. The only way around it is to make your UI modular by using UIAnchors. There are many examples of this, including two videos and the very first example that comes with NGUI.

jeldrez

  • Sr. Member
  • ****
  • Thank You
  • -Given: 8
  • -Receive: 4
  • Posts: 352
    • View Profile
Re: Using UIStretch with a manual height UIRoot
« Reply #6 on: January 11, 2013, 12:17:37 AM »
Well, I used the UIStretch for the background texture and the button and it works.
So, thanks anyway!

moursbourn

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Using UIStretch with a manual height UIRoot
« Reply #7 on: January 21, 2013, 06:09:01 PM »
There does seem to be a bug.  I am in 2.27c.

If you attach a uistretch to a sprite with a widget container set and the root is set to automatic it works.  The sprite stretches to the size of the widget.  If you set the root to manual the sprite stretches off into space.

It is also wrong if you set the root to automatic but the min height is greater than the player resolution height.  example: (auto on, min height =500, player set to iPhone Tall (320x480))=wrong
« Last Edit: January 21, 2013, 06:19:10 PM by moursbourn »

andrew

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: Using UIStretch with a manual height UIRoot
« Reply #8 on: January 22, 2013, 01:18:27 AM »
Is this UIStretch attached to a widget, or attached to the widget's parent...  because experimenting, I had the same problem ( stretched into space ) if I added the UIStretch to the parent object of my sliced sprite.  When I moved it to the sliced sprite object, it worked as expected.

Incidentally.. I think this solved my posted question regarding "how do I set up a UISlicedSprite to fill the screen"

moursbourn

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Using UIStretch with a manual height UIRoot
« Reply #9 on: January 22, 2013, 01:49:57 AM »
it is attached to the widget.  sliced sprite.  set to horizontal stretch to a label widget  that has it's width set to 0 so that the line grows as text is entered into it.