Author Topic: same height of sprite on various aspect ratios?  (Read 3358 times)

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
same height of sprite on various aspect ratios?
« on: August 31, 2012, 05:01:04 AM »
Hi!

I am making a vertical scrollview and it works fine but when i tried it on the phone it does not go all the way down to the bottom
of the screen. i used top-right anchor so it stays in that position.

I tried to use UIStrech but i dont know where to put it and how to set clipping on the dragPanel based on new height?
Any help appreciated!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: same height of sprite on various aspect ratios?
« Reply #1 on: August 31, 2012, 02:16:38 PM »
UIStretch can't be used for this, as you need to stretch clipping and it doesn't do that. You need to write a custom script to resize clipping in this case.

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
Re: same height of sprite on various aspect ratios?
« Reply #2 on: August 31, 2012, 02:22:50 PM »
can you point me in the right direction, i am not sure how i would do this, but i would try

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: same height of sprite on various aspect ratios?
« Reply #3 on: August 31, 2012, 02:30:46 PM »
Panel's clipping area is defined by UIPanel.clipRange. XY is position (center), ZW is width and height (extents). To move the clipping area 20 units vertically, adjust Y by 10, and W by 20.

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
Re: same height of sprite on various aspect ratios?
« Reply #4 on: August 31, 2012, 02:38:18 PM »
ok, but how to know how many units to move? how to know the center? use Screen.width and height?
also what to do with the clippanel background? to use UIStrech on it?

it seems hard to do for me, but it's worth the effort i think

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: same height of sprite on various aspect ratios?
« Reply #5 on: August 31, 2012, 02:51:57 PM »
The units are in pixels. You know Screen.height, you know the current dimensions.

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
Re: same height of sprite on various aspect ratios?
« Reply #6 on: September 01, 2012, 05:41:20 AM »
here is what i tried

i put this code on the the container for dragable panel (consists of background,dragablepanel and slider)

  1. void Start () {
  2.                 Vector3 tmp = this.transform.localPosition;
  3.                 tmp.y = Screen.height / 2;
  4.                 this.transform.localPosition = tmp;
  5.         }

i tried various options for anchor most sense was right, but i tried also center.
i thouth that if i set it to center and then set the localPosition to the half of the screen then i would be able to get panel in the right center for all devices but it always somehow sticks to top. i hope that i could resolve this, then what is left to somehow scale the whole panel so it fits the height of the screen....

is this possible, and i am going in the right direction? thanks for looking into this. i was wondering how others are doing this, since it is not something specific.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: same height of sprite on various aspect ratios?
« Reply #7 on: September 01, 2012, 06:31:13 AM »
As I mentioned, you shouldn't be moving the panel. You should be adjusting its clipRange instead. Leave the transform at (0, 0, 0).

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
Re: same height of sprite on various aspect ratios?
« Reply #8 on: September 01, 2012, 11:25:29 AM »
ok this is what i did:

  1. void Start () {
  2.  
  3.                 Vector4 tmp = this.GetComponent<UIPanel>().clipRange;
  4.                 tmp = new Vector4(0,0,0,Screen.height);
  5.                 this.GetComponent<UIPanel>().clipRange = tmp;
  6.                
  7.                 this.GetComponent<UIDraggablePanel>().ResetPosition();
  8.                
  9.         }

and it works very good! thank you for guidance!

thought there are several other things, i do not have idea how to stretch the vertical slider that controls the draggable panel. i managed to stick it to the right side of the screen in it is always in the middle. do i need to scale it somehow or use UIStrech? i want it to be from the top to the bottom of the screen as with draggable panel.

thanks again for looking into this, great product, forum and support!