playMaker

Author Topic: SOLVED!! Centering gui elements, whatever screensize.  (Read 11101 times)

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
SOLVED!! Centering gui elements, whatever screensize.
« on: July 12, 2013, 06:41:43 PM »
Seems simple but I cant make a robust system.
I have a centered cursor (no problem there, is automatic when you set cursor, and click lock cursor)

Now Im displaying text, when the cursow rolls over an item you can interact with. Im useng gui label. and got it lined up, but if a resize the window, the cursor remains centered but the text moves.

I tried:
GuilLayout Begin Begin Area (default settings)
GuiLayout Begin Centered
Gui Label (that contains my stuff)
Gui Layout end centered
GuiLayout  End Area

But its still moving if I resize...

What am I getting wrong here...?

OR?????
Can I somehow LOCK some gui to the cursor? The Cursor is locked anyway! I cant use guiFollow, cos.. er wheres the game object of the cursor? but something else?

Thanks

Mark
« Last Edit: August 15, 2013, 03:16:01 PM by markfrancombe »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Centering gui elements, whatever screensize.
« Reply #1 on: July 15, 2013, 02:55:34 AM »
Hi,

 Have you tried "GUILayoutBeginAreaFollowObject", where the object is following your mouse?

bye,

 Jean

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Centering gui elements, whatever screensize.
« Reply #2 on: July 19, 2013, 06:07:28 PM »
No I havent... I just figured there would be a way of locking stuff to center.. but OK.. feels like a workaround, but sure my Cursor IS Centered, so it should work!

...FEW MINUTES LATER...

Hmm.. please see attatched... Why is this not showing up? In previous implementation, I specifically had to type screen coords in, (which changed depending on screensize) Here I specify Cursor, and keep rest at default, thinking Cursor will be counted as 0,0.

Possibly my text is Waaaaay off screen, but not sure!


Mark
« Last Edit: July 19, 2013, 07:07:42 PM by markfrancombe »

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
MORE centering issues...
« Reply #3 on: July 22, 2013, 07:38:23 PM »
OK cant get to the bottom of this!

Firstly, a NORMAL gui label shows up, t center it on the screen I set 0.5 for left, and 0.5 for top, and set to normalised.
I WOULD THINK this should be enough, arnt i setting it to start its text block at those normalised coordinates?
Anyway? It looks OK, but then if I tweaked the screen size around, so does the text, NOT centered on my mouse (which is locked to the center using Set mouse cursor)

SO I try something. How about I Get MouseX and Y and see what they are? For some reason, X is ok. 0.5 but Y is 0.5253724 (or close) When I resize the screen X (0.5) stays as it is, but Y is variable? Why is this? Is not Lock Cursor (in the set cursor Action) supposed to lock the cursor?

I then try anyway to set the offsets of the gui label using these mouse X and Y, but that gives similar results to just setting manually.. still moves!

I tried the GUILayoutBeginAreaFollowObject thing as you suggested, but never see any text... as I said in my last post, either the text is Waaaay off the screen somewhere, or ive done something wrong!

Mark



markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Centering gui elements, whatever screensize.
« Reply #4 on: July 24, 2013, 11:22:59 AM »
Still need help with this...

Bqlqzs

  • Junior Playmaker
  • **
  • Posts: 52
Re: Centering gui elements, whatever screensize.
« Reply #5 on: July 24, 2013, 11:59:53 AM »
Hello

If you want fixed element on screen after you resize the screen, :

Actions: (All actions need Every Frame on, that work realtime)

Get Screen Height/Width
(store the values in float) example: screen width=600

Float Divide
(Width/Height) example: 600/2 you get the actual screen center value =300

Float Subtract
(the Width/Height float) example: if your panel are 160width, You subtract 80 from (Height/Width 300)

After you get : actual you get (max screen) / 2 (center) - (panel Half) = full centered panel at realtime


You can align from center
« Last Edit: July 24, 2013, 12:05:09 PM by Bqlqzs »

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Centering gui elements, whatever screensize.
« Reply #6 on: August 02, 2013, 05:39:31 AM »
gonna try this, thanks...

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Centering gui elements, whatever screensize.
« Reply #7 on: August 05, 2013, 05:36:53 PM »
One more question,
Gui Label has Left Top Width Height.. for setting position, how do I turn what you gave me above, into these? Or Do I just set them all to 0, and the the Gui Label START from the center??
Plus you mean that I have to do all this TWICE, once for height and once for Width?

Thanks so much for you help, but Im REAL surprised there aint a action for this!
 ;D

Mark

« Last Edit: August 05, 2013, 05:41:45 PM by markfrancombe »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Centering gui elements, whatever screensize.
« Reply #8 on: August 06, 2013, 04:02:38 AM »
Hi,

 We overlooked the set of official actions :) it's all there for this to be achieved.

Please find a scene showing a perfectly center label, screen size agnostic! Basically, it's just that:

GuiLayoutBeginArea
GuiLayoutBeginCentered
-- STUFF GOES HERE
GuiLayoutEndCentered
GuiLayoutEndArea

Bye,

 Jean

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Centering gui elements, whatever screensize.
« Reply #9 on: August 11, 2013, 07:49:52 PM »
Yeah, I tried that. Of course i didnt tell whole story  :P

What I need is for the gui label to start printing a tiny bit right of center.
Central is my cursor ( a dot) it becomes active when you roll over stuff you can interact with (a small circle) This is set elsewhere, an empty GO with global transitions, one for each state the cursor can be in.
So as the cursor becomes active, RIGHT next to it the text label of the appropriate action appears (Open Door?). It needs to NOT be totally centered (cos thats the cursors space) but slightly to the right.

Using the technique you suggested, if I adjust the position slightly using the GuiLayout begin area Left and Top.. It DOESNT remain centred if you resize the window.
Should it?

Mark

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Centering gui elements, whatever screensize.
« Reply #10 on: August 12, 2013, 05:00:00 AM »
Hi,

it should. not sure what happens here.

the other way, and likely the best way given what you are describing now is to use absolute positioning and GUI ( Not GUILAyout) actions

get the screen width and height
divide them by two, you have your center. do this on update to always be centered ( ONLY if you know the user can change the app size, else no need)

and use GUILabel and position it in pixels, then it will be ALWAYS centered, and you can add labels around, by simply defining offsets


also, simply use GUITexture, thea are a lot easier to position using screen relative position combined with inset offset. that's what I would do instead of using gui action purely.


bye,

 Jean
bye,

 Jean

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Centering gui elements, whatever screensize.
« Reply #11 on: August 12, 2013, 05:17:58 AM »

get the screen width and height
divide them by two, you have your center. do this on update to always be centered ( ONLY if you know the user can change the app size, else no need)

and use GUILabel and position it in pixels, then it will be ALWAYS centered, and you can add labels around, by simply defining offsets
Seems like that was what Bqlqzs was suggesting above, I had trouble with that too, but Ill give it a go again.
Quote
also, simply use GUITexture, thea are a lot easier to position using screen relative position combined with inset offset. that's what I would do instead of using gui action purely.
 Jean

HUH? Gui Texture only shows ... er... textures. Are you suggesting I make my labels as textures? But they write themselves... using HOTween string.
I actually was thinking of this, , and having a "Handwritten" look, but went away from it, I dont think you were suggesting that either, so... please elaborate?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Centering gui elements, whatever screensize.
« Reply #12 on: August 12, 2013, 07:26:45 AM »
Hi,

 you can have text using GuiText, just like GuiTexture. Simply go to the unity menu "GameObject/Create/Gui Text"

and you'll have all you need to center on screen, AND having an offset based on that center, using Pixel Offset.

Bye,

Jean

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Centering gui elements, whatever screensize.
« Reply #13 on: August 12, 2013, 05:26:21 PM »
Hi,

 you can have text using GuiText, just like GuiTexture. Simply go to the unity menu "GameObject/Create/Gui Text"

and you'll have all you need to center on screen, AND having an offset based on that center, using Pixel Offset.

Sorry for being dense, but IM still not getting it. Are you saying that after finding the center position (screen height and width and halving it) I should add a gui text for my label?

OR.. Are you saying that I should lose ALL this centering calculation, add a gui text alone, and then use its controls to do all the adjustments?

Trying this latest... seems simple...

Mark

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Centering gui elements, whatever screensize.
« Reply #14 on: August 12, 2013, 05:55:44 PM »
UPDATE;

Ok I tried the adding a SetGuiText, it asked for a guitect component, I clicked, it added one. Set my text variable, Went to the GuiText Component and added my font (its dynamic so I leave all else blank).

When I run it, I can see that the SetGuiText Action is getting my String OK. (the typed effect using Hotween) But nothing is being drawn on screen.

I suppose this is a GuiText thing rather than a PlayMaker thing, but not sure what my next move is?