@Acumen, give it a try and see if it works. I believe (but don't quote me on this) that Unity does squarify non-square textures (definitely so for PVR as they only support square). If the image is squarified all your UV's will be wrecked and you will know right away.
For anyone interested, the PanelBasedRoot branch on Github was just updated and will most definitely become the mainline branch real soon. It has support for grouping elements into a parent (for easy animations of multiple items) and most importantly it supports an unlimited number of texture atlases. The API will remain identical for a single texture atlas but there are a few changes to it when using multiple (each sprite needs to know where its mama is). There is a demo scene included showing 2 atlases in one scene.
Good lord o larkie, its working! Thanks Prime!@hippo, here are the exact steps to follow:
- create and export font bitmap and config file from Hiero
- rename the .fnt file to "myfont.txt" and rename the .png file to "myfont.png"
- create a new Texture Packer document and drag the exported png file from Hiero into it
- set the data file name in Texture Packer to "myatlas"
- export from Texture Packer then rename the exported myatlas.json file to "myatlas.txt"
- drag the myfont.txt, myatlas.txt and myatlas.png files to a Resources folder
- set the texturePackerConfigName in the inspector to myatlas
- create a UIFont with: var text = new UIText( "myfont", "myfont.png" );
Awesome! Once you do it once it's simple every time thereafter. And regenerating with new sprites is quick also.
Did i understand this correctly that you managed to put the font on the same atlas as the other game relevant gui items ? That'd be great
We could fit all the highscore and timer fonts on one atlas
Can you confirm this, hippocoder ?
You can put your font and all the rest of your UI on one atlas. That is correct.
Last edited by Eskema; 05-07-2011 at 03:37 PM.
It's great stuff. In my own iphone game I actually just used LoadImage(filename, optionalAtlas=null);
And it would basically load images and pack them all onto an atlas in realtime but we can't do that in unity without making this library pro only. It is a much more funky choice if you are interested in super small distributables since you don't duplicate anything. But these days with Infinity Blade on appstore taking up a gig, who's counting?
private var text1:UITextInstance;
- function Start()
- //load the font
- var text = new UIText( "myfont", "myfont.png" );
- // spawn new text instances showing off the relative positioning features by placing one text instance in each corner
- var x:float = UIRelative.xPercentFrom( UIxAnchor.Left, 0, 0);
- var y:float = UIRelative.yPercentFrom( UIyAnchor.Top, 0, 0 );
- text1 = text.addTextInstance( "hello man. I have a line\nbreak", x, y );
But text1 = text.add throws an error (Assets/scripts/Game.js(17,37): BCE0023: No appropriate version of 'UIText.addTextInstance' for the argument list '(String, float, float)' was found.)...
is this library c# only?
@hippocoder, the next push will have all the optional params removed temporarily until MonoDevelops bug is fixed.
Yet another excellent tool from you prime.
Regarding positioning of gui elements, is there an easy way to center an object on the screen, horizontally, vertically, or both? I couldn't see an easy way to do this, but perhaps i'm blind.
@Matkins, there is a positionCenter method along with the other relative positioning methods. They are all in a class of extension methods for easy perusing. The same goes for the animation methods. The filename will give it away because it will end with "Extensions" to indicate that it is extension methods.
@Earl, no forcing. Just a firm suggestion. It will make your life easier in the long run
Prime: I started with C++ and really fell in love with just a simple life of js :P I will probably get nagged by mike_mac or Neil Carter on IRC to go C# at some point. But I think optional parameters lead to messy code anyway
@hippo, the thing is I fail to see how JS is simpler. It lacks features available to C#, doesn't have anywhere near functioning code complete and it doesn't exist outside of the Unity world. That alone is reason enough to go C# let alone the myriad other reasons.
I'm old and stubborn. When you get to my age, young prime, you'll see. Hee hee. Having said that I'll port to c later tonight I guess.
Question: how do get the actual on-screen width of a string displayed? The reason for this is because I want to generate buttons under the text, which can be tapped
I'd rather prioritise text size than button size for this particular way of working as it will be several lines of text which need to be a set size. Do you have methods exposed to return the rendered bounds of a particular piece of rendered text.