- Home /
EZ Gui positioning
Right guys, i'm having problems with the EZGui positioning.
If i position my object to where i want it in a large screen i.e. (1280x800 landscape) then it doesn't position correct for the smaller screen size (480x320 landscape)
I'm trying to figure out the issue. It's hard to tell how you cropped these images. I'm guessing that the script is working, but that 100 pixels is a much larger percentage of 480x320 screen than a 1280x800 screen. If this is the case, you might have to write a script that sets the x and y values based on a percentage of the screen width/height. According the the reference, you would then need to call PositionOnScreen().
how would i set the x and y values like that? whats the actual algorithm coz its confusing me. screen width/height = ... and then ???
and where do i add this code in? Should i write it in Start function()...or shud i just write it in the update function()? hmmm confusing coz im not sure when i should be calling the PositionOnScreen()
thank you for your time :)
Answer by robertbu · Mar 30, 2013 at 06:14 PM
Here is a bit of C# code to demonstrate. It would be attached to the same object as the placement script and be part of the Start() method for the class. I'm away from my desk, so I cannot test it.
void Start() {
int width = (int)((float)Screen.width / 1280.0f * 100.0f);
int height = (int)((float)Screen.height / 800.0f * 100.0f);
EZScreenPlacement ezsp = GetComponent<EZScreenPlacement>();
exsp.PositionOnScreen(width, height, 356.4116);
}
The third parameter is based on your settings above. I think it will be ignored since you have "IgnoreZ" set, but I don't know without playing with it.
This is what I hand in $$anonymous$$d. I can take a closer look at EZ Screen Placement this evening if it is not working. Click on the object at both resolutions. What is the Screen Pos when you look at the EZ Screen Placement component?
at screen resolution 1280x800 the screen pos x=73 y=43 and at screen resolution 480x320 the screen pos x=37 y=40 <--- at this screen resolution the placement is correct. However for some reason as i increase the screen resolution, the x position seems to move too much towards the right
thank you
There is an issue with the code I gave you: it should be -100 rather than 100 in the height calculation. But that does not account for what you are seeing. Change to use -100. Then put in a debug statement for width and height:
Debug.Log("width="+width+", height="+height);
For 1280 x 800, the width/height should be 100,-100. If they are, compare these values with the values you get in the inspector for Screen Pos for the EZ Screen Placement component.