Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: finky45 on March 06, 2014, 10:01:44 AM
-
I am using a single atlas that contains all my menu graphics, as well as the font I am using for the game. The problem is that the Font Descriptor file (TextAsset) created by BMFont does not take into consideration the offset in the atlas. So NGUI renders random parts of my image. I looked in the examples provided with NGUI and noticed that the Font Descriptor file has a global offset already added to the x and y coordinates. How do I add that offset to the descriptor file without manually editing it?
I found no such option in BMFont and I don't know if TP can do that work for me. The funny thing is NGUI shows the correct area for the text in the preview. If I could just specify an offset or have it intelligently render it (atlas xml offset + font x,y = correct letter coordinates) that would be great.
-
What is it you're doing exactly? The correct process is:
1. Export your font from BMFont, generating a FNT file and the associated texture.
2. Use the Font Maker in NGUI to create your font, adding it to the atlas as desired.
Also note that you don't need to use BMFont anymore. You can just generate the same exact bitmap font inside Unity by opening up the Font Maker.
-
1. Export your font from BMFont, generating a FNT file and the associated texture.
-Done that, it was the easy part. BMFont doesn't and can't possibly know ahead of time where the final sprite will be located in an atlas. Therefor the x and y coordinates are as if the font sprite was by itself.
2. Use the Font Maker in NGUI to create your font, adding it to the atlas as desired.
-I tried this and it produced the same problem, except that it moved the sprites around the atlas.png in a different manner than TP.
The problem is simple as stated above: the font.fnt file doesn't take the global sprite offset into account after it's added to an atlas. The x and y coordinates in the .fnt file at 0,0 where the font sprite in the atlas is further down at around 0,400.
-
The FNT file shouldn't have to know anything about an atlas, because there is no atlas.
Atlas gets created from the FNT file and the exported texture. The texture's size should not be modified between the export from BMFont and the creation of an NGUI font.
Once the font has been created and chosen to be added to an atlas, NGUI automatically switches to using the sprite within the atlas rather than the original texture. And the sprite does have the offset you're talking about.
-
The FNT file shouldn't have to know anything about an atlas, because there is no atlas.
Yes, this is exactly what I said ::)
Atlas gets created from the FNT file and the exported texture. The texture's size should not be modified between the export from BMFont and the creation of an NGUI font.
This is correct.
Once the font has been created and chosen to be added to an atlas, NGUI automatically switches to using the sprite within the atlas rather than the original texture. And the sprite does have the offset you're talking about.
The sprite has the offset but the individual letters are still bound as if the sprite was a single texture!!!!! It's looking for them in the wrong part of the atlas they are further down. Why is it so hard to understand?
-
As I mentioned, NGUI uses the sprite's offset and applies it to the values imported from the FNT file, thus getting the correct letter positions.
I've made you a video of the full process: http://www.youtube.com/watch?v=BvEftEDeR-o
-
It seems that I have an older version of NGUI because the process differs slightly from your video (thank you for taking the time to make it, I really appreciate it). Maybe there was a bug or something in my version because I'm following the same procedure. We'll see.
Edit: Well after closing Unity and opening it the font appeared coorectly o.O I guess we can call this solved but I don't know why/how it got fixed. I still have to update NGUI so I will be doing that later...