Author Topic: Dynamic Font Z-sorting  (Read 9916 times)

ivomarel

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 53
    • View Profile
Dynamic Font Z-sorting
« on: April 26, 2013, 04:48:35 AM »
Dear all,

I have a problem with the new dynamic font, which I am using in both my panels and my main screen. It seems like there can be only one dynamic font in the scene. Even with different TTF's, different GameObjects, I can not manage to have two different dynamic fonts.

Mostly this a problem because of Z-sorting. The text in the main screen is now always in front of my panels.

Any ideas on how to fix this? Or is this actually fixed in NGUI 2.6.0 ? I'm using the dynamic font package right now.

dlewis

  • Guest
Re: Dynamic Font Z-sorting
« Reply #1 on: April 26, 2013, 06:58:24 AM »
The reason the dynamic fonts are in front of the panels is because they have their own draw call so need to be sorted with z position.

ivomarel

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: Dynamic Font Z-sorting
« Reply #2 on: April 26, 2013, 09:04:00 PM »
Hey dlewis,

Thanks for your reply. As I have been trying to adjust the Z-position of my widgets, the problem is that they seem to Z-sort all together. Meaning if I move my UILabel to a higher Z-position, so it's behind the panel all other UILabels (from inside the panel) move as well.

Note: My UI is packed together all in one atlas.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic Font Z-sorting
« Reply #3 on: April 26, 2013, 09:06:22 PM »
If you need to separate a specific group of widgets, give them an extra panel. Like so for example:

Window (panel)
- Background
- Title
- Title Text (z = -1)
-- Child (panel, z = -2)
--- Background
--- Content Text (z = -1, cumulative makes it -3)

ivomarel

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: Dynamic Font Z-sorting
« Reply #4 on: April 26, 2013, 10:11:49 PM »
Yes that worked - Thanks ArenMook!

Irin1178

  • Guest
Re: Dynamic Font Z-sorting
« Reply #5 on: May 08, 2013, 02:24:16 PM »
When I attempt to setup my scene like this, the ui elements under the child a panel do not render. The UIPanel says there are widgets and draw calls taking place, but nothing visible. Removing the UIPanel script allows them to render again.

Am I missing something?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic Font Z-sorting
« Reply #6 on: May 08, 2013, 05:32:51 PM »
3D UI? In 3D UIs everything is sorted by distance to camera, and you shouldn't use dynamic fonts/multiple panels at all. 2D UI works correctly.

Irin1178

  • Guest
Re: Dynamic Font Z-sorting
« Reply #7 on: May 08, 2013, 06:00:54 PM »
2D ui, and yeah, im using dynamic fonts for my text. So that is likely the issue.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic Font Z-sorting
« Reply #8 on: May 08, 2013, 06:09:06 PM »
If it's 2D, then it should be fine. Keep in mind with dynamic fonts, they are sorted by depth, so you have to move them forward (negative Z).

kevork

  • Guest
Re: Dynamic Font Z-sorting
« Reply #9 on: May 08, 2013, 06:19:33 PM »
Was running into this even when using z values to sort. Turns out it, that UILabel::MakePositionPerfect is rounding the z value to the nearest int.  There should probably either be a disclaimer to use whole numbers for z sorting or just remove pos.z = Mathf.RoundToInt(pos.z);

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Dynamic Font Z-sorting
« Reply #10 on: May 09, 2013, 08:17:24 AM »
Use whole numbers for z sorting. :)

kevork

  • Guest
Re: Dynamic Font Z-sorting
« Reply #11 on: May 09, 2013, 03:08:57 PM »
That is great information Nicki! What I'm suggesting is that information exists in the warning messages showed by NGUI.  For example, "When adjusting the Z, lower value means closer to the camera." could just have 'use whole numbers' appended to it.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Dynamic Font Z-sorting
« Reply #12 on: May 09, 2013, 05:17:50 PM »
You're right and I agree.