How do I calculate the text height in a CCLabel in design units?

AlanTonissonAlanTonisson AUMember ✭✭

I have a scene with just one label using a true-type font. It renders at a different size on iOS and Android.
How can I determine the actual size so I can calculate the correct font scaling factor?
I don't care about minor variations in how font sizes are interpreted on different platforms, but I don't want to have to test everything on a few dozen platforms and devices and write custom code for each one. It defeats the purpose of having a platform independent framework with a device independent coordinate system.
I set the DesignResolution to get platform independent coordinates:

int width = 640;
int height = 960;
GameView.DesignResolution = new CCSizeI(width, height);

In my Scene I create a layer and add a CCLabel:

label = new CCLabel(Translate("Tap to Play"), "Arial", 36) { IgnoreAnchorPointForPosition = false };
AddChild(label);

But CClabel's font size does not scale relative to design units. What coordinate system is the font size relative to?

This discussion: Font size is way too small on Android suggests that there is no definitive answer.
Is there a definitive way to scale the fonts proportionally with design units?

I noticed that I can globally scale the text in CCLabels using:
CCLabel.DefaultTexelToContentSizeRatio = SomeScaleFactor;
But I don't know how to set 'SomeScaleFactor' to make the text size sensible on each platform and device.

Any help would be appreciated.

Thanks.

Best Answer

  • AlanTonissonAlanTonisson AUMember ✭✭
    edited November 5 Accepted Answer

    Font size for CCLabels does seem to be scaled relative to design units at least per platform, so that's not much trouble.

    I'm now just setting CCLabel.DefaultTexelToContentSizeRatio by trial and error based on the platform and I'm ignoring the device resolution. - Works on all the iPhone models I tried in the simulator.

Answers

  • AlanTonissonAlanTonisson AUMember ✭✭
    edited November 5 Accepted Answer

    Font size for CCLabels does seem to be scaled relative to design units at least per platform, so that's not much trouble.

    I'm now just setting CCLabel.DefaultTexelToContentSizeRatio by trial and error based on the platform and I'm ignoring the device resolution. - Works on all the iPhone models I tried in the simulator.

  • AlanTonissonAlanTonisson AUMember ✭✭

    Why do I feel like I'm talking to myself?

Sign In or Register to comment.