Odd GUI positioning

Sorry if this has been covered before somewhere . . . I was unable to locate it with the limited patience I have at this point.

I’m trying to use a Label to create a fullscreen splash screen using Unity iPhone Basic 1.5. Normally I would just use GUITexture, but I’m trying to respect Unity’s decision to phase out the old GUI system in favor of this new one. But really, why’s it gotta be so much more complicated???

Anyway, the iPhone’s screen resolution is reported to be 480 x 320 pixels. So I’ve created an image that is 480 x 320 pixels and is used in the following code:

var splashTexture : Texture2D;	// Texture for the splash screen (needs to be 480 by 320)
                                 // 'cause GUI.Label doesn't resize anything either :P

function OnGUI () {
	// Draws the splash screen
	GUI.Label(Rect(0, 0, 480, 320), splashTexture);
}

Seems like that would work, but alas I get a small border around my image when the code is run (about 3 pixels wide on top and bottom and about 10 pixels wide on the right side – seems to be flush on the left side).

If I use the following as my code:

...
	GUI.Label(Rect(0, -3, 480 + 10, 320 + 10), splashTexture);
...

The image fills the screen correctly.

Can anyone tell me why the GUI.Label seems to draw a 3-4% smaller area than the size it’s given with a height offset of about 3 pixels?

. . . For now I’m gong to eschew the whole thing and simply draw planes with materials on them, at least then I can get exact scaling and positioning. I’d still like to know what’s going on with that GUI.Label if possible, though . … I’m trying! :frowning:

Thanks,
~Rob

GUI.Label() (and other GUI[Layout] functions) use GUIStyles to determine how they draw content. Among other things, a GUIStyle defines how much space will border every element so as not to look crowded. By default, GUI.Label() uses the style GUI.skin.label to draw, but you can provide any style you want using the GUI.Label(Rect, Texture, GUIStyle) version of the function. In your case, and empty GUIStyle will do exactly what you want, so you can use:

GUI.Label(Rect(0, 0, 480, 320), splashTexture, GUIStyle.none);

This bit of the Unity manual explains everything in more detail.

Finally, I’m not sure where you got the impression that GUITexture was being phased out, but it definitely isn’t. GUITexture is an excellent way of doing what you’re trying to do without any code, and with less processor overhead.

Thanks Daniel,

I also found GUI.DrawTexture did what I wanted (including the resizing feature).

Useful to know that you can specify a blank GUIStyle.

Also, the discussion of phasing out GUITexture and GUIText comes from Nicholas’ post (third from the top) in the this Topic: http://forum.unity3d.com/viewtopic.php?t=7675 which I’d remembering reading at the time. I don’t know if that’s changed since then, as I’m not up on my current events : )

Thanks again,
~Rob

Well, that’s what I get for speaking in absolutes. I’m not convinced it’s going anywhere, though, as Unity has to maintain backwards compatibility, and it’s the easiest way to display 2D images without writing any code.

I agree with the latter for sure : )

FWIW, the backwards compatibility argument says nothing about them sticking around in perpetuity as the way we branch our player we can make them disappear completely in v3.0 without ever breaking any 1.x or 2.x content if that’s what we chose to do.

With that in mind, we’re not there yet as we don’t have proper feature parity. But Nich’s statements still hold true and we will, over time, phase out GUIText and GUITextures as UnityGUI gets more robust in terms of features and optimized in terms of performance.

Oh, and this whole thread belongs in UnityGUI so I’m moving it there now… :slight_smile: