LabelTTF does not work with CCDirector.SharedDirector.ContentScaleFactor

Topics: Windows Phone 8
Apr 30, 2014 at 5:56 PM
Edited Apr 30, 2014 at 6:11 PM
I have some CCLabelTTF at my CCScene and it works fine. But if I set
CCDirector.SharedDirector.ContentScaleFactor = 1070f / preferredWidth;
then I have many errors in output like those:
An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
A first chance exception of type 'Microsoft.Xna.Framework.Content.ContentLoadException' occurred in MonoGame.Framework.DLL
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll
An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
A first chance exception of type 'System.IO.FileNotFoundException' occurred in MonoGame.Framework.DLL
And there is no more any CCLabelTTF at screen, but everything else works fine. Is anybody had the same issue?

(I have 2 months old version of cocos2d-xna)
May 1, 2014 at 6:54 AM
Edited May 1, 2014 at 7:22 AM
I think there is a bug in the CCLabelTTF class:

https://github.com/Cocos2DXNA/cocos2d-xna/blob/master/cocos2d/label_nodes/CCLabelTTF.cs#L245
        private void updateTexture()
        {
            CCTexture2D tex;

            // Dump the old one
            if (Texture != null)
            {
                Texture.Dispose();
            }

            // let system compute label's width or height when its value is 0
            // refer to cocos2d-x issue #1430
            tex = new CCTexture2D();

            var result = tex.InitWithString(m_pString,
                               m_tDimensions.PointsToPixels(),
                               m_hAlignment,
                               m_vAlignment,
                               m_pFontName,
                               m_fFontSize * CCMacros.CCContentScaleFactor());
(last one line)

If I have for example CCLabelTFF with font size 50 (and arial-50.spritefont (or xnb) for this label) and I have CCContentScaleFactor = 2.22f, then
m_fFontSize * CCMacros.CCContentScaleFactor() = 111,
then I need arial-111.spritefont. But this is not good. I think it should work by the other way.
Coordinator
May 1, 2014 at 7:39 AM
in order to properly use TTFLabel, you must first initialize the font.

sample:
            CCSpriteFontCache.FontScale = 0.6f;
            CCSpriteFontCache.RegisterFont("arial", 12, 16, 50);
            CCSpriteFontCache.RegisterFont("MarkerFelt", 16, 18, 22);
May 1, 2014 at 7:51 AM
I did't now that
thank you
May 5, 2014 at 4:53 PM
Now it works, but anyway I have many of these
An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
A first chance exception of type 'Microsoft.Xna.Framework.Content.ContentLoadException' occurred in MonoGame.Framework.DLL
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll
An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
A first chance exception of type 'System.IO.FileNotFoundException' occurred in MonoGame.Framework.DLL
To avoid this exceptions I made some changes in the CCSpriteFontCache.cs
https://github.com/grishaandrianov/cocos2d-xna/commit/e3dff99bbaaa8c60f6f9ac81fd1452cc202a4947