HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: [Resolved] GUI position shift on re-scale  (Read 2825 times)

MarlonB

  • General Accounts
  • *
  • Posts: 38
    • View Profile
[Resolved] GUI position shift on re-scale
« on: Dec 03, 12, 02:00:04 PM »

Hi all.

I have this weird problem that I've been trying to crush for 2 days now :)

Scaling up or down a GUI moves it across the screen instead of keeping it's x/y position.
I did not specify docks nor anchors.


posX = 200, posY = 200 , scale = 1




I scale it down by 20%
posX = 200, posY = 200, scale = 0.8




It shifted slightly to the left and up ... even though x and y are the same.
I also noticed that when scaling down or up, the size does not change (in options). The size remains 681,79


What am i missing here :)


« Last Edit: Dec 04, 12, 06:26:43 PM by HE-Cooper »
Logged
Cerberus of The Repopulation.

katoomm0m0

  • General Accounts
  • *
  • Posts: 44
    • View Profile
Re: GUI position shift on re-scale
« Reply #1 on: Dec 03, 12, 03:13:32 PM »

When you scale the GUI component, you scale the x and y axis also. That is why, when you scale it down 20% it moves to the left and up. To maintain its original position on the screen you need to add +20% to its x and  y position.

- Claus
Logged
- Claus

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: GUI position shift on re-scale
« Reply #2 on: Dec 03, 12, 04:03:59 PM »

Claus is right: scaling happens to both size AND position.  So, you can compensate and adjust the position, or here is a tip I often use:

Make the thing to be scaled a child of a _panel and make the child's position 0,0.  Then when you scale it, its position inside of the parent is unchanged, since 0,0 never changes from scaling.  Meanwhile you can still position the parent panel anywhere on screen.

And if you like, you can set the child to have horizontal and/or vertical autocentering on so that as it scales it stays centered relative to the parent panel.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

MarlonB

  • General Accounts
  • *
  • Posts: 38
    • View Profile
Re: GUI position shift on re-scale
« Reply #3 on: Dec 04, 12, 12:41:51 AM »

Thanks for the tips!


I'm still slightly confused though :)

My gui component's posX and posY is the position on the viewport?
If yes, why does it draw in another place while in both cases (0.8 and 1) the posX and posY were equal?


To test this, after opening the GUI (in playmode) i outputted it's details before and after scaling ... in both cases it has the same posX and posY ... yet it is somewhere else on the sreen :)

If you say the axes also scale ... which axes are you talking about?
Logged
Cerberus of The Repopulation.

katoomm0m0

  • General Accounts
  • *
  • Posts: 44
    • View Profile
Re: GUI position shift on re-scale
« Reply #4 on: Dec 04, 12, 02:33:01 AM »

Its correct that your x and y position values for the object remains the same even after it 'moved' after you scaled it. This is because, like I said, the axis is scaled also. Maybe this explanation will help: imagine that every scale has its own 'local' coordinate system, so everything placed in the viewport with scale 0.8 is using the same coordinate system, and objects with scale 1.0 is using another etc.

A bit like if you hold down ctrl and scroll with your mouse in the browser, everything is retaining position values etc. but is becoming bigger/smaller while still being anchored in upper left corner.

I hope this helped, English is not my first language so i hope this made some sense.

- Claus
Logged
- Claus

MarlonB

  • General Accounts
  • *
  • Posts: 38
    • View Profile
Re: GUI position shift on re-scale
« Reply #5 on: Dec 04, 12, 03:10:31 AM »

Ah yes, it's clear to me now. Each scaled component has it's own "grid".



Vielen dank.
Logged
Cerberus of The Repopulation.

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: [Resolved] GUI position shift on re-scale
« Reply #6 on: Dec 04, 12, 11:43:24 PM »

Quote
My gui component's posX and posY is the position on the viewport?
No, position is relative to the control's parent.  So it is only the position in the viewport if it is a child of the gui layer, or each control from parent to parent up to the top are all at 0,0.

So, if the top-most control is at 500,100 and it has a child at 25,25, the child's position in the viewport would be at 525,125.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.