x


How do I scale GUI object for retina display if they are not in OnGUI?

Currently my scene has GUITextures as object, created from the GameObject menu, not dynamically generated in OnGui.

The problem with this is that the code for bumping assets up to retina size, only works on GUIText / GUITextures generated in OnGui and not GUIText / GUITextures that are from the GameObjects menu.

How can I make it so any GUI element in my scene will use the Matrix4x4.identity.Scale command?

more ▼

asked Jul 15 '11 at 08:18 AM

hawken gravatar image

hawken
91 19 24 25

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

GUITexture is resolution-independent provided you use the Transform to position and scale instead of the pixelInset rectangle.

more ▼

answered Jul 15 '11 at 08:20 AM

Waz gravatar image

Waz
6.5k 23 33 71

I'm using iTween to move them about, so they need to be dropped in as game objects in the hierarchy and not built in code.

Jul 15 '11 at 08:25 AM hawken

Yes, that's fine. In the inspector are you using the Pixel Inset to position them, or the Transform fields?

Jul 15 '11 at 08:37 AM Waz

ah I see, so pixel inset is a no no for the re-scaling code below? If I do move them around using transform, I'm also wondering, how can I then make them double the size?

Jul 15 '11 at 08:43 AM hawken

Change the scale.

Jul 15 '11 at 10:23 AM Waz

care to elaborate a little? I'm not really sure what the code for that might be for this. I get an error because Scale is not part of GameObject.

Jul 18 '11 at 08:02 AM hawken
(comments are locked)
10|3000 characters needed characters left

heres the retina code that works when GUI objects are built inside it

function OnGUI() {
    var screenScale: float = Screen.width / 320.0;
    var scaledMatrix: Matrix4x4 = Matrix4x4.identity.Scale(Vector3(screenScale,screenScale,screenScale));
    GUI.matrix = scaledMatrix;
    GUI.Label( Rect( 0, 0, 480, 20 ), "test");
}
more ▼

answered Jul 15 '11 at 08:29 AM

hawken gravatar image

hawken
91 19 24 25

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3808
x2021
x18

asked: Jul 15 '11 at 08:18 AM

Seen: 2664 times

Last Updated: Jul 19 '11 at 11:22 AM